Beats 100% DFS + heap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```kotlin []\n/**\n * Example:\n * var ti = TreeNode(5)\n * var v = ti.`val`\n * Definition for a binary tree node.\n * class TreeNode(var `val`: Int) {\n *     var left: TreeNode? = null\n *     var right: TreeNode? = null\n * }\n */\nclass Solution {\n    fun kthLargestPerfectSubtree(root: TreeNode?, k: Int): Int {\n        if(root == null)return -1\n\n        val heap = PriorityQueue<Int>(k)\n        fun dfs(node:TreeNode?):Int{\n            if(node == null)return 0\n            val leftDepth = dfs(node.left)\n            val rigthDepth = dfs(node.right)\n            if(leftDepth == rigthDepth){\n                heap.add(2*leftDepth + 1)\n                if(heap.size > k)heap.remove()\n                return 2*leftDepth + 1\n            }\n            return -1\n        }\n\n        dfs(root)\n\n        return if(heap.size == k)heap.remove() else -1 \n    }\n}\n```
['Kotlin']