🚀 iterative solution beats many users in c++
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```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    int height(TreeNode* root){\n        if(!root){\n            return 0;\n        }\n        int max_h = 0;\n        int leafs = 0;\n        int size = 0;\n        stack<pair<TreeNode*,int>>s;\n        s.push({root,0});\n        while(!s.empty()){\n            auto [temp,h] = s.top();s.pop();\n            size++;\n            if(!temp->left && !temp->right){\n                leafs++;\n                max_h = max(max_h,h);\n            }\n            if(temp->right){\n                s.push({temp->right,h + 1});\n            }\n            if(temp->left){\n                s.push({temp->left,h + 1});\n            }\n        }\n        if(pow(2,max_h) == leafs){\n            return size;\n        }\n        return -1;\n    }\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        priority_queue<int>pq;\n        queue<TreeNode*>q{{root}};\n        while(!q.empty()){\n            TreeNode* temp = q.front();q.pop();\n            int res = height(temp);\n            if(res != -1){\n                pq.push(res);\n            }\n            if(temp->right){\n                q.push(temp->right);\n            }\n            if(temp->left){\n                q.push(temp->left);\n            }\n        }\n        int ans = -1;\n        if(k > pq.size()){\n            return -1;\n        }\n        while(k -- && !pq.empty()){\n            ans = pq.top();pq.pop();\n        }\n        return ans;\n    }\n};\n```
['C++']