Maximum Depth of Binary Tree — Trees

Count the levels in a hierarchy, measuring from the head of the structure to its deepest member; an empty one has no levels.

Trees · Easy

The problem

How many levels deep does a company org chart go, counting from the top? The depth of a binary tree is the number of nodes on its longest downward path from the root to a leaf. Return the depth of the given tree.

The story

An HR team wants to know how many layers their org chart has. The chart is a tree of up to 1500 people, where each person has at most two direct reports. Count the people on the longest chain from the top down to someone with no reports. An empty chart has depth 0, and one person alone has depth 1.

What to return

Constraints

Example

Input
root = [8,4,12,null,6,9,15,null,null,null,7]
Output
4

Solve it

More in Trees

All algorithm problems