Simple Priority queue || C++
\n\n# Code\n\nclass Solution {\npublic:\n    pair<int,bool> recur(TreeNode* root,priority_queue<int,vector<int>,greater<int>> &pq,int k){\n        if(root==NULL
\n\n# Code\n```\nclass Solution {\npublic:\n    pair<int,bool> recur(TreeNode* root,priority_queue<int,vector<int>,greater<int>> &pq,int k){\n        if(root==NULL){\n            return {0,true};\n        }\n        pair<int,bool> left=recur(root->left,pq,k);\n        pair<int,bool> right=recur(root->right,pq,k);\n        if(left.first==right.first&&left.second&&right.second){\n            int height=1+max(left.first,right.first);\n            int ans=pow(2,height)-1;\n            if(pq.size()<k){\n                pq.push(ans);\n            }\n            else if(ans>pq.top()){\n                pq.pop();\n                pq.push(ans);\n            }\n            return {height,true};\n        }\n        return {1+max(left.first,right.first),false};\n    }\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        priority_queue<int,vector<int>,greater<int>> pq;\n        recur(root,pq,k);\n        return pq.size()>=k?pq.top():-1; \n    }\n};\n```
['C++']