DFS. Solution without sorting. O(n)
Time O(n), space O(n)
Time $O(n)$, space $O(n)$
```
class Solution:
    def kthLargestPerfectSubtree(self, root: Optional[TreeNode], k: int) -> int:
 
        def dfs(root):
            if not root:
                return 0
            l = dfs(root.left)
            r = dfs(root.right)
            if l == r >= 0:
                if len(high_tree) == l:
                    high_tree.append(1)
                else:
                    high_tree[l] += 1
                return l + 1
            return -1

        total, high_tree = 0, []
        dfs(root)
        for high_tree, cnt_tree in zip(count(len(high_tree), -1), reversed(high_tree)):
            total += cnt_tree
            if total >= k:
                return (1 << high_tree) - 1
        return -1
```
['Python3']