PostOrderTraverse with Size.
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int kthLargestPerfectSubtree(TreeNode root, int k) {
        int[] r = postOrderSize(root);

        Collections.sort(res, Collections.reverseOrder());
        if (k > res.size()) {
            return -1 ;
        }
        return res.get(k - 1);
    }

    public ArrayList<Integer> res = new ArrayList<>();

    public int[] postOrderSize(TreeNode root) {
        if (root == null) {
            return new int[]{0, 0};
        }

        int[] left = postOrderSize(root.left);
        int[] right = postOrderSize(root.right);

        int depth = left[0] == right[0]? left[0] + 1 : 0;
        int number = 1 + left[1] + right[1];

        if(perfect(depth, number)) {
            res.add(number);
        }

        return new int[]{depth, number};
    }

    public boolean perfect(int depth, int number) {
        return depth != 0 && (number == (1 << depth) - 1);
    }
}
```
['Java']