Easy Solution
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 dfs(TreeNode* node, vector<int>& v) {\n        if(node == NULL) return 0;\n\n        int lt = dfs(node->left, v);\n        int rt = dfs(node->right, v);\n\n        int ans = -1;\n        if(lt == rt) ans = lt+rt+1;\n\n        v.push_back(ans);\n        return ans;\n    }\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        vector<int> ans;\n        int a = dfs(root, ans);\n\n        if(k>ans.size())return -1;\n        sort(ans.begin(),ans.end(),greater<int>());\n        return ans[k-1];\n    }\n}; \n```
['C++']