Python Simple Post-Order traversal
Intuition\nLike any tree problem, it is best to first identify if any known tree traversal technique can fit the solution.\nIn this case, we notice that we are 
# Intuition\nLike any tree problem, it is best to first identify if any known tree traversal technique can fit the solution.\nIn this case, we notice that we are processing child nodes first and then parent, so some version of post order traversal would fit this.\nThis is because the parent is a valid subtree only if all children are valid subtrees.\n\n# Approach\nPerform post-order traversal of the tree returning the child node count if the right and left subtree have the same number of node.\nIf there is a mismatch, simply return -1 to indicate invalid to the parent\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$ -> Due to sorting result\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```python3 []\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n\n    def getHeight(self, node):\n\n        if node is None:\n            return 0\n\n        left_height = self.getHeight(node.left)\n        right_height = self.getHeight(node.right)\n\n        # If left and right subtree height is same, then its valid subtree\n        if left_height == right_height and left_height != -1:\n            self.result.append(1+left_height+right_height)\n            return 1+left_height+right_height\n\n        # Arbitrary return if left and right subtree heights don\'t match\n        return -1\n\n    def kthLargestPerfectSubtree(self, root: Optional[TreeNode], k: int) -> int:\n\n        self.result = []\n        self.getHeight(root)   \n\n        if k > len(self.result):\n            return -1\n\n        return sorted(self.result, reverse=True)[k-1]\n\n\n\n```
['Python3']