Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Subtree

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.

Constraints

  • Compare structure, not only values.

Examples

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

advanced

Subtree

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.