Inorder Traversal + Priority_Queue
Intuition\n Describe your first thoughts on how to solve this problem. \nto check for perfect binary ensure each parent must have two children at same levels , 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nto check for perfect binary ensure each parent must have two children at same levels , for kth largest we can use maxheap for storing size for easy retrieval\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTraversing each node and check for perfect binary tree at each node and if it is then store the size in priority queue max heap, if not then that node is not counted as perfect binary subtree\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(2n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nint solve(TreeNode* root, priority_queue<int>&pq){\n    if(root == NULL) return 0;\n    int left = solve(root->left,pq);\n    int right = solve(root->right,pq);\n    if(left == -1 || right == -1) return -1;\n    if(left == right) {\n        pq.push(left+right+1);\n        return left+right+1;\n    }\n    return -1;\n}\nclass Solution {\npublic:\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        priority_queue<int>pq;\n        int x = solve(root,pq);\n        int cnt = 0,ans = -1;\n        if(k > pq.size()) return ans;\n        while(!pq.empty()){\n            cnt++;\n            if(cnt == k){\n                ans = pq.top();\n                break;\n            }\n            pq.pop();\n        }\n        return ans;\n    }\n};\n```
['C++']