Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

112. Maximum Depth of Binary Tree

EasyDay 33 of 60Trees & BST

Given the root of a binary tree, return its maximum depth: the number of nodes on the longest path from the root down to a leaf. An empty tree has depth 0.

Example 1
Input: root = [3,9,20,null,null,15,7]
Output: 3
The path 3, 20, 15 has three nodes.
Example 2
Input: root = [1,null,2]
Output: 2
Constraints
  • The number of nodes is in the range 0 to 10^4
  • -100 <= Node.val <= 100
Hints
Frequently asked at: Amazon, LinkedIn, Apple, TCS
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min