Skip to content

Practice K-th Largest Perfect Subtree Size in Binary Tree

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3319
LeetCode Problem

K-th Largest Perfect Subtree Size in Binary Tree

Problem Statement

You are given the root of a binary tree and an integer k. Return an integer denoting the size of the kth largest perfect binary subtree, or -1 if it doesn't exist. A perfect binary tree is a tree where all leaves are on the same level, and every parent has two children.

Source: K-th Largest Perfect Subtree Size in Binary Tree on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [5,3,6,5,2,5,7,1,8,null,null,6,8], k = 2
Output
3

# Example 2

Input
root = [1,2,3,4,5,6,7], k = 1
Output
7

# Example 3

Input
root = [1,2,3,null,4], k = 3
Output
-1

Constraints

The number of nodes in the tree is in the range [1, 2000].
1 <= Node.val <= 2000
1 <= k <= 1024

Related LeetCode Problems

Practice more problems similar to K-th Largest Perfect Subtree Size in Binary Tree.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.