Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Solution: Maximum Depth (or Height) of Binary Tree
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given a root node of the binary tree, return the depth (or height) of a binary tree.

The Depth of the binary tree refers to the number of nodes along the longest path from the root node to the farthest leaf node. If the tree is empty, the depth is 0.

Examples

Example 1

  • Input: root = [1, 2, 3, 4, 5]
  • Expected Output: 3
  • Explanation: The longest path is 1->2->4 or 1->2->5 with 3 nodes.

Example 2

  • Input: root = [1, null, 2, null, 3]
  • Expected Output: 3
    • Justification: There's only one path `1->2->3

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible