Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Maximum Depth of Binary Tree
00:00
5 left

Maximum Depth of Binary Tree

EasyPython

Problem

Given the root of a binary tree, return its maximum depth as an integer. The maximum depth is the number of nodes along the longest path from the root node down to any leaf node. If the tree is empty, return 0.

Constraints

  • The number of nodes in the tree is in the range [0, 10^4]
  • -100 <= Node.val <= 100
  • The tree may be empty

Function Signature

def max_depth(root=None, val=None, left=None, right=None):
Interviewer

Your question is Maximum Depth of Binary Tree. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.