C++ solution DFS post-order traversal
\n// Please, upvote if you like it. Thanks :-)\nclass Solution {\npublic:\n    int checkSubtrees(TreeNode* root, vector<int>& res) {\n        if (!root)\n      
```\n// Please, upvote if you like it. Thanks :-)\nclass Solution {\npublic:\n    int checkSubtrees(TreeNode* root, vector<int>& res) {\n        if (!root)\n            return 0;\n        int leftChildren = checkSubtrees(root->left, res);\n        int rightChildren = checkSubtrees(root->right, res);\n        if (leftChildren != rightChildren ||\n            leftChildren < 0 || rightChildren < 0)\n            return -1;\n        int curTreeSize = 1 + leftChildren + rightChildren;\n        res.push_back(curTreeSize);\n        return curTreeSize;\n    }\n    \n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        vector<int> res{};\n        checkSubtrees(root, res);\n        sort(begin(res), end(res), [] (auto a, auto b) {\n            return a > b;\n        });\n        return k <= res.size() ? res[k - 1] : -1;\n    }\n};\n```
['Depth-First Search', 'Recursion', 'C', 'Sorting', 'Binary Tree', 'C++']