Sobes.tech
Junior — Senior

Finding the maximum height of a binary tree

livecode

Task condition

The method should determine how tall (deep) the maximum height of a given binary tree is, starting from its root node TreeNode root.

       4
      / \
     10  23
    /
   12
  /
 6

Expected result for the given example: 3.

public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {}

    TreeNode(int val) {
        this.val = val;
    }
}

class TreeDepthFinder {
    public static int maxDepth(TreeNode root) {
        return 0; // TODO
    }
}