Core Concepts || Easy Implementaion
Code
# Code
```java []
class Solution {
    ArrayList<Integer> sizes;
    class Pair {
        boolean isPerfect;
        int size;
        Pair(boolean isPerfect, int size){
            this.isPerfect = isPerfect;
            this.size = size;
        }
    }
    Pair isPerfectTree(TreeNode root){
        if(root == null) return new Pair(true, 0);
        Pair left, right;
        left = isPerfectTree(root.left);
        right = isPerfectTree(root.right);
        if(left.isPerfect && right.isPerfect && left.size == right.size && left.size != -1){
            int size = left.size+right.size+1;
            sizes.add(size);
            return new Pair(true, size);
        }
        return new Pair(false, -1);
    }
    public int kthLargestPerfectSubtree(TreeNode root, int k) {
        this.sizes = new ArrayList<>();
        isPerfectTree(root);
        k--;
        if(k<sizes.size()){
            Collections.sort(sizes, (a, b)->b-a);
            System.out.print(sizes);
            return sizes.get(k);
        }else{
            return -1;
        } 

    }
}
```
['Tree', 'Depth-First Search', 'Sorting', 'Binary Tree', 'Java']