DFS | Postorder traversal | C++
Intuition\n\nIf a tree is a perfect tree, then its subtree will also be a perfect subtree with same height. \n\n\n# Code\ncpp []\n/**\n * Definition for a binar
# Intuition\n\nIf a tree is a perfect tree, then its subtree will also be a perfect subtree with same height. \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    vector<int> res ;\n    int solver(TreeNode* node) {\n        if (!node) {\n            return 0;\n        } else {\n            int left = solver(node->left);\n            int right = solver(node->right);\n            \n            if (left == right) {\n                res.push_back(left+right+1) ;\n                return left+right+1 ;\n            } else {\n                return -1 ;\n            }\n        }\n    }\n\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        solver(root);\n        sort(res.begin(),res.end()) ;\n        return k > res.size() ? -1 : res[res.size()-k] ;\n    }\n};\n```
['Tree', 'Depth-First Search', 'C++']