Graph Theory37 sections · 1633 units
Open in Course

LeetCode 104 Maximum Depth of Binary Tree - Problem Statement

LeetCode 104

Problem: Maximum Depth of Binary Tree Task: You are given the root of a binary tree. Return the maximum depth (the number of nodes along the longest path from the root to any leaf). This is a classic tree DP problem. You solve it recursively by asking: what is the depth of the left subtree?

What is the depth of the right subtree? Take the maximum and add 11 for the current node. The base case is a null node, which has depth 00. This runs in O(n)O(n) time and O(h)O(h) space where hh is the height.