Tap here to switch tabs
Problem
Submissions

Problem: K-th Largest Perfect Subtree Size in Binary Tree

Try to solve the K-th Largest Perfect Subtree Size in Binary Tree problem.

Statement

Given the root of a binary tree and an integer k, return the kextthk^{ ext{th}} largest size of a perfect binary subtree in the tree. If there are fewer than k perfect binary subtrees, return −1-1.

A subtree of a binary tree is perfect if all of its internal nodes have exactly 22 children and all of its leaf nodes share the same depth. The size of a subtree is the total number of nodes it contains.

Constraints:

  • The number of nodes in the tree is in the range [1,2000][1, 2000].

  • 1≤1 \leq Node.val ≤2000\leq 2000

  • 1≤1 \leq k ≤1024\leq 1024

⋮
Tap here to switch tabs
Problem
Submissions

Problem: K-th Largest Perfect Subtree Size in Binary Tree

Try to solve the K-th Largest Perfect Subtree Size in Binary Tree problem.

Statement

Given the root of a binary tree and an integer k, return the kextthk^{ ext{th}} largest size of a perfect binary subtree in the tree. If there are fewer than k perfect binary subtrees, return −1-1.

A subtree of a binary tree is perfect if all of its internal nodes have exactly 22 children and all of its leaf nodes share the same depth. The size of a subtree is the total number of nodes it contains.

Constraints:

  • The number of nodes in the tree is in the range [1,2000][1, 2000].

  • 1≤1 \leq Node.val ≤2000\leq 2000

  • 1≤1 \leq k ≤1024\leq 1024