Answer: Airbnb OA Question 2024 July | Trees | on-campus
Answer · Posted Jun 2026
Solution: Maximum Depth of Binary Tree — Recursive DFS Approach We use Recursive Depth First Search (DFS). The maximum depth of a tree rooted at any node is defined as: depth(node) = 1 + max(depth(node.left), depth(node.right)) Base case: If the node is null, its depth is 0. Recursive case: Recursively compute the depth of the left and right subtrees, take the maximum, and add 1 for the current node. This naturally propagates the correct depth up the entire tree through ...
The full answer & interview discussion are available to premium members.
Log in Create a free account