Python data engineering interview problem. Difficulty: advanced. Pattern: Trees. About 18 minutes. Part of the Pro drill bank.
Whether sub is a subtree of root (level-order inputs). Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement is_subtree(root: list, sub: list) -> bool.
Input: is_subtree([3, 4, 5, 1, 2], [4, 1, 2]) Output: True Left subtree matches.
Topics: lakebench, python, subtree, dfs.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Whether sub is a subtree of root (level-order inputs).
Implement `is_subtree(root: list, sub: list) -> bool`. Example: root `[3, 4, 5, 1, 2]`, sub `[4, 1, 2]` → `True`. Keep the harness.