Python data engineering interview problem. Difficulty: beginner. Pattern: Recursion. About 10 minutes. Free to practice.
Flatten arbitrarily nested lists without splitting strings. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement flatten(nested) that flattens nested lists to any depth into one list of leaf values. Strings must stay whole (do not iterate characters).
Input: flatten([1, [2, [3, 4]], 5]) Output: [1, 2, 3, 4, 5] Nested lists unwrap left-to-right.
Topics: lakebench, python, flatten, lists.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Flatten arbitrarily nested lists without splitting strings.
Implement `flatten(nested)` that flattens nested lists to any depth into one list of leaf values. Strings must stay whole (do not iterate characters). Example: `[1, [2, [3, 4]], 5]` → `[1, 2, 3, 4, 5]`. Keep the harness prints.