Max Depth
Python data engineering interview problem. Difficulty: advanced. Pattern: Trees. About 18 minutes. Part of the Pro drill bank.
Maximum depth of a binary tree from level-order input. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
A pipeline tree can be shallow or deeply nested. Its depth tells you how many dependency levels a traversal must pass through. Return the maximum number of nodes on a path from the root to a leaf. Decode the level-order list and ignore missing children. Write max_depth(level_order: list) -> int. The tree [3, 9, 20, None, None, 15, 7] has 3 levels, so its depth is 3. The starter file already has the function name and harness print lines. Keep them and fill only the function body.
Requirements
- Count nodes, not edges, on the longest root-to-leaf path.
- Ignore None child slots.
- Return 0 for an empty tree.
Constraints
- The tree is represented in level order and values may be integers.
- The return type is int.
Examples
Input: max_depth([3, 9, 20, None, None, 15, 7]) Output: 3 Root to 15/7 is depth 3.
Topics: lakebench, python, depth, dfs.
More Python interview questions · All interview problems · Learn data engineering
Max Depth
Interview-style drill: Maximum depth of a binary tree from level-order input.
Implement `max_depth(level_order: list) -> int`. Example: `[3, 9, 20, None, None, 15, 7]` → `3`. Keep the harness.