Python Solution that beats 99.9%
Intuition\n Describe your first thoughts on how to solve this problem. \nIf a root node is perfect, then both left and right sub-tree is perfect and there size 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf a root node is perfect, then both left and right sub-tree is perfect and there size (node count) should be same. Use heap to store the k-th largest sizes.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(k)$$\n\n# Code\n```python3 []\n\nclass Solution:\n    def kthLargestPerfectSubtree(self, root: Optional[TreeNode], k: int) -> int:\n\n        validSizes = [] # min-heap\n\n        def dfs(node): \n            # returns (size, isBalance)\n            \n            if not node:\n                return (0, True) \n\n            sizeL, isBalanceL = dfs(node.left)\n            sizeR, isBalanceR = dfs(node.right)\n\n            if (sizeL == sizeR) & isBalanceL & isBalanceR:\n                size = sizeL + sizeR + 1\n                nonlocal validSizes\n                heapq.heappush(validSizes, size)\n                if len(validSizes) > k:\n                    heapq.heappop(validSizes)\n                return (size, True)\n\n            return (0, False)\n\n        dfs(root)\n\n        return validSizes[0] if len(validSizes) == k else -1\n            \n        \n```
['Python3']