Skip to content

Latest commit

 

History

History

finding-the-maximum-depth-of-a-binary-tree

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Finding the maximum depth of a binary tree

The maximum depth of a binary tree is the number of nodes from the root down to the furthest leaf node. In other words, it is the height of a binary tree.

Input

1, 2, 3, 4, -1, 5, 6, -1, -1, -1, -1, 7, 8, -1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, -1, -1, -1, 11, -1

Above array means below binary tree. An empty node is displayed as -1.

    1
   / \
  2   3
 /   / \
4   5   6
   / \   \
  7   8   9
     /   /
    10  11

Output

4

Execute

node solution.js