Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Flatten Nested Lists

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).

Requirements

  • Preserve left-to-right leaf order.

Constraints

  • nested may contain ints, strings, and further lists.
  • Do not split strings into characters.

Examples

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

beginner

Flatten Nested Lists

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.