Example 1 : Find height of a binary tree

TopicDifficultyCompanies
Binary Tree
EASY
Amazon
Goldman Sachs

Given a binary tree, write a program to find the maximum depth of the binary tree.

Problem Note

  • The maximum depth is the number of nodes along the longest path from the root node to leaf node.
  • A leaf is a node with no child nodes.

Example

Input: Given binary tree, 
[5, 3, 6, 2, 4, -1, -1, 1, -1, -1, -1, -1, -1]
5
/ \
3 6
/ \
2 4
/
1
Output: return its depth = 4

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.