Recursion || DFS || Easy to Understand
Approach\nUsing basic dfs to visit each node , cheking left subtree , right subtree and if the subtree are perfect binary trees then it is a Perfect Binary Tree
# Approach\nUsing basic dfs to visit each node , cheking left subtree , right subtree and if the subtree are perfect binary trees then it is a **Perfect Binary Tree .**\n\nUsing **MaxHeap** to store sizes of all such perfect binary trees.\n\n# Complexity\n- Time complexity: O(N logN) : \n O(N) for travesing each node  and if we consider the time complexity logN for the insertion of each node .\n\n- Space complexity: O(N) : for recursive stack\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 solve(TreeNode* root, priority_queue<int> &maxHeap) {\n        \n        if(root == NULL)\n            return 0;\n\n        int leftH = solve(root->left, maxHeap);\n        int rightH = solve(root->right, maxHeap);\n        \n        if(leftH == -1 || rightH == -1 || leftH != rightH)\n            return -1;\n\n        int totalNodes = leftH + rightH + 1;\n        maxHeap.push(totalNodes);\n\n        return totalNodes;\n    }\n\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        priority_queue<int> maxHeap;\n        solve(root, maxHeap);\n\n        while(k > 1 && !maxHeap.empty()) {\n            maxHeap.pop();\n            k--;\n        }\n\n        if(maxHeap.empty()) return -1;\n        \n        return maxHeap.top();\n    }\n};\n\n```\nPlease Upvote !!!!\n
['Depth-First Search', 'C++']