golang best solution 99%
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```golang []\n\n// isPerfect checks if the subtree rooted at node is a perfect binary tree and returns its size\nfunc isPerfect(node *TreeNode) (bool, int) {\n if node == nil {\n  return true, 0\n }\n\n // Check left and right subtree\n leftPerfect, leftSize := isPerfect(node.Left)\n rightPerfect, rightSize := isPerfect(node.Right)\n\n if leftPerfect && rightPerfect && leftSize == rightSize {\n  // The current node forms a perfect subtree\n  return true, leftSize + rightSize + 1\n }\n\n // If it doesn\'t form a perfect subtree\n return false, 0\n}\n\n// kthLargestPerfectSubtreeSize returns the k-th largest perfect binary subtree size\nfunc kthLargestPerfectSubtree(root *TreeNode, k int) int {\n var sizes []int\n\n var collectSizes func(node *TreeNode)\n collectSizes = func(node *TreeNode) {\n  if node == nil {\n   return\n  }\n\n  // Check if the current subtree is a perfect binary tree\n  if perfect, size := isPerfect(node); perfect {\n   sizes = append(sizes, size)\n  }\n\n  // Continue traversing left and right\n  collectSizes(node.Left)\n  collectSizes(node.Right)\n }\n\n // Collect sizes of all perfect binary subtrees\n collectSizes(root)\n\n // Sort sizes in descending order\n sort.Sort(sort.Reverse(sort.IntSlice(sizes)))\n\n // If k is valid, return the k-th largest size\n if k <= len(sizes) {\n  return sizes[k-1] // k-1 for zero-based indexing\n }\n\n return -1 // Not enough perfect binary subtrees\n}\n```
['Go']