#3319

K-th Largest Perfect Subtree Size in Binary Tree

medium · 62.2% accepted · 153 likes · top 63%

tree · depth-first search · sorting · binary tree

⊣ practice⊣ open on leetcode ↗

Description

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.

Solution