Clean & Simple Solution✅
Code\ncpp []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNod
# 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 */\nclass Solution {\npublic:\n    priority_queue<int,vector<int>,greater<int>>pq;\n    int isPerfect(TreeNode* root, int k){\n        if(!root) return 0;\n        int lSub=isPerfect(root->left,k);\n        int rSub=isPerfect(root->right,k);\n\n        if(lSub!=-1 && lSub==rSub){\n            pq.push(lSub+1);\n            if(pq.size()>k)pq.pop();\n            return lSub+1;\n        }\n        return -1;\n    }\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        isPerfect(root,k);\n        return pq.size()>=k?pow(2,pq.top())-1:-1;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Sorting', 'Binary Tree', 'C++']