Java Solution DFS + Recursion
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) {
        List<Integer> list = new ArrayList<>();
        helper(root, list);
        if(k > list.size()){
            return -1;
        }
        Collections.sort(list, Collections.reverseOrder());
        return list.get(k - 1);
    }
    private int helper(TreeNode node, List<Integer> list){
        if(node == null){
            return 0;
        }
        int left = helper(node.left, list);
        int right = helper(node.right, list);
        if(left == right){
            list.add(left + right + 1);
            return left + right + 1;
        }
        return -1;
    }
}
```
['Java']