Easy 🌳||java||DFS||
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nimport java.util.*;\n\nclass Solution {\n    public int kthLargestPerfectSubtree(TreeNode root, int k) {\n        List<Integer> sizes = new ArrayList<>();\n        getPerfectSubtreeSizes(root, sizes);\n        sizes.sort((a, b) -> b - a);\n        return sizes.size() >= k ? sizes.get(k - 1) : -1;\n    }\n\n    private int getPerfectSubtreeSizes(TreeNode node, List<Integer> sizes) {\n        if (node == null) return 0;\n\n        int leftSize = getPerfectSubtreeSizes(node.left, sizes);\n        int rightSize = getPerfectSubtreeSizes(node.right, sizes);\n\n        if (leftSize == rightSize && (node.left == null || node.right != null)) {\n            int subtreeSize = 1 + leftSize + rightSize;\n            sizes.add(subtreeSize);\n            return subtreeSize;\n        }\n        return -1;\n    }\n}\n\n```
['Tree', 'Depth-First Search', 'Sorting', 'Binary Tree', 'Java']