Min Heap  + post-order Traversal Sol.  O(NlogK) - (DFS) 
Approach
pre-order traversal with heap to store only topK elements.
Complexity
Time complexity: O(NlogK)

Space complexity: O(K) - extra but O(N)
Code
# Approach
- pre-order traversal with heap to store only topK elements.

# Complexity
- Time complexity: $$O(NlogK)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(K)$$ - extra but $$O(N)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def postorder(self, root, heap, k):
        if(root == None):
            return 0
        left = self.preorder(root.left, heap, k)
        right = self.preorder(root.right, heap, k)
        
        if(left == right):
            totalNodes = left + right + 1
            if(len(heap) == k):
                val = heap[0]
                if(val < totalNodes):
                    heappop(heap)
                    heappush(heap,totalNodes)
            else:
                heappush(heap,totalNodes)
            return totalNodes
        return -1

    def kthLargestPerfectSubtree(self, root: Optional[TreeNode], k: int) -> int:
        minHeap = []
        self.postorder(root, minHeap, k)
        if(len(minHeap) < k):
            return -1
        else:
            minHeap = sorted(minHeap,reverse=True)
            return minHeap[k-1]
        
```
['Backtracking', 'Tree', 'Depth-First Search', 'Sorting', 'Heap (Priority Queue)', 'Binary Tree', 'Python3']