Skip to main content
All Visualizers
#LC 104•Trees•Easy

Maximum Depth of Binary Tree

Return the maximum number of nodes along a path from the root to a leaf.

Understand the problem

Return the maximum number of nodes along a path from the root to a leaf.

Example 1

Input: {"root": [3, 9, 20, null, null, 15, 7]}

Output: 3

Follow the trace to see how the algorithm reaches this result.

Constraints

  • Use the input format shown in the example.
Think first

What information should you keep so you can solve the next step efficiently?

Pattern tags:Tree DFSRecursion
Time: O(n)Space: O(h)
Step 1 of 6 • Use Left/Right arrows or Space to control