Search
⌘K

Leetcode 104. Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth — the number of nodes along the longest root-to-leaf path. This classic easy problem is solved by a DFS or level-order traversal in O(n) time (n ≤ 10^4).

Asked at:

LinkedIn

LinkedIn

Google

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late February, 2026

LinkedIn

LinkedIn

Mid-level

Given a tree, determine its depth; that is the number of nodes in the path from the root to the farthest leaf. Please fill in the following function to find the max depth of a tree using the following Node API. (GIVEN) Abstract class that holds a tree node """ # class Node { # def getValue() -> int; # def getLeft() -> Node: // May return null if no left/right child exists # def getRight() -> Node; // May return null if no left/right child exists # }

Mid October, 2024

Google

Google

Junior

Calculate the depth of a binary tree

Comments

Your account is free and you can post anonymously if you choose.