DFS
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```csharp []
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left;
 *     public TreeNode right;
 *     public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
public class Solution {
    private List<int> res;
    private (bool, int) DFS(TreeNode root)
    {
        if(root == null)
            return (false, 0);

        if(root.left == null && root.right == null)
        {
            res.Add(1);
            return (true, 1);
        }

        var leftSub = DFS(root.left);
        var rightSub = DFS(root.right);
        if(!leftSub.Item1 || !rightSub.Item1 || leftSub.Item2 != rightSub.Item2)
            return (false, 0);

        int curTotal = 1+2*leftSub.Item2;
        res.Add(curTotal);
        return (true, curTotal);
    }
    public int KthLargestPerfectSubtree(TreeNode root, int k) {
        res = new List<int>();
        DFS(root);
        if(k > res.Count)
            return -1;

        res = res.OrderByDescending(x=>x).ToList();
        return res[k-1];
    }
}
```
['C#']