Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Maximum Depth of Binary Tree

Easy
treebinary-treedfsrecursion

Return the maximum depth of a binary tree — the number of nodes on the longest root-to-leaf path.

Input: one line — the tree in level order, null for missing children. Output: the depth (0 for an empty tree).

Example 1
Input:
3 9 20 null null 15 7
Output:
3
Example 2
Input:
1 null 2
Output:
2

Constraints

  • 0 ≤ number of nodes ≤ 10^4
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.