Java solution by simple post order traversal in O(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 
# 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:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public class Subtree{\n        boolean isp ;\n        int height ;\n        int size ;\n        public Subtree(boolean isp , int height , int size){\n            this.isp = isp;\n            this.height = height;\n            this.size = size;\n        }\n    }\n    public int kthLargestPerfectSubtree(TreeNode root, int k) {\n        PriorityQueue<Integer> q = new PriorityQueue<>();\n        help(root , k , q);\n        return q.size() < k ? -1 : q.peek();\n    }\n    public Subtree help(TreeNode node, int k , PriorityQueue<Integer> q){\n        if(node == null){\n            return new Subtree(true , -1 , 0);\n        }\n\n        Subtree left = help(node.left , k , q);        \n        Subtree right = help(node.right , k , q);  \n\n        boolean isp = left.isp && right.isp && (left.height == right.height);\n        int height = Math.max(left.height , right.height) + 1;\n        int size = left.size + right.size + 1;\n\n        if(isp){\n            if(q.size() < k){\n                q.offer(size);\n            }else{\n                q.offer(size);\n                q.poll();\n            }\n        }\n\n        return new Subtree(isp , height , size);\n    }\n}\n```
['Java']