using simple recursion c++ 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 \n{\npublic:\n\nint fun(TreeNode* root, int k, vector<int>&res)\n{\n    if(root==NULL){\n        return 0;\n    }\n    int val1 = fun(root->left, k, res);\n    int val2 = fun(root->right, k, res);\n    if(val1!=-1 && val1==val2)\n    {\n        int val = val1+val2+1;\n        res.push_back(val);\n        return val;\n    }\n    else\n    {\n        return -1;\n    }\n\n}\n\n    int kthLargestPerfectSubtree(TreeNode* root, int k) \n    {\n        vector<int>res;\n        fun(root,k,res);\n        sort(res.begin(),res.end());\n        reverse(res.begin(),res.end());\n        if((int)res.size()<k)\n        {\n            return -1;\n        }\n        int idx = k-1;\n        int val = res[idx];\n\n        return val;\n    }\n};\n```
['Recursion', 'C++']