Python data engineering interview problem. Difficulty: advanced. Pattern: Trees. About 18 minutes. Part of the Pro drill bank.
Invert a binary tree given as a level-order list. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement invert_tree(level_order: list) -> list. Input/output use level-order lists with None for missing children (trailing Nones may be omitted).
Input: invert_tree([4, 2, 7, 1, 3, 6, 9]) Output: [4, 7, 2, 9, 6, 3, 1] Children swapped at every node.
Topics: lakebench, python, invert, level-order.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Invert a binary tree given as a level-order list.
Implement `invert_tree(level_order: list) -> list`. Input/output use level-order lists with `None` for missing children (trailing Nones may be omitted). Example: `[4, 2, 7, 1, 3, 6, 9]` → `[4, 7, 2, 9, 6, 3, 1]`. Keep the harness.