#3319
K-th Largest Perfect Subtree Size in Binary Tree
specialist · 690 · lc medium +30 · 62.2% accepted · 153 likes · top 63%
Description
You are given the root of a binary tree and an integer k.
Return the size of the kth largest perfect binary subtree, or -1 if no such subtree exists.
A perfect binary tree is one in which every internal node has exactly two children and all leaf nodes reside at the same depth.
Code
1
2
3
4
5
6
7
8
9