Example: N‐Ary max depth - rFronteddu/general_wiki GitHub Wiki

// depth-first search approach
class Solution {
    public int maxDepth(Node root) {
        if (root == null) {
            return 0;
        }
        int depth = 0;
        
        for (var c : root.children) {
            int currDepth = maxDepth(c);
            if (currDepth > depth) {
                depth = currDepth;
            }
        }
        return depth + 1;
    }
}