Java contest soultion Beast 65%
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\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$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 */\n\nclass TreeNode {\n    int val;\n    TreeNode left;\n    TreeNode right;\n\n    TreeNode(int val) {\n        this.val = val;\n    }\n}\nclass Solution {\n    public int kthLargestPerfectSubtree(TreeNode root, int k) {\n        \n   List<Integer> perfectSubtreeSizes = new ArrayList<>();\n        findPerfectBinarySubtrees(root, perfectSubtreeSizes);\n        \n        \n        Collections.sort(perfectSubtreeSizes, Collections.reverseOrder());\n        \n        \n        return k > perfectSubtreeSizes.size() ? -1 : perfectSubtreeSizes.get(k - 1);\n    }\n\n    private int findPerfectBinarySubtrees(TreeNode node, List<Integer> sizes) {\n        if (node == null) {\n            return 0;\n        }\n\n      \n        int leftSize = findPerfectBinarySubtrees(node.left, sizes);\n        int rightSize = findPerfectBinarySubtrees(node.right, sizes);\n\n      \n        if (leftSize == rightSize && leftSize != -1) {\n    \n            int currentSize = 1 + leftSize + rightSize;\n            sizes.add(currentSize);\n            return currentSize;\n        }\n        \n       \n        return -1;\n    }\n}\n```
['Java']