Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Flatten a directory listing into paths

Python data engineering interview problem. Difficulty: intermediate. Pattern: Recursion. About 15 minutes. Part of the Pro drill bank.

A directory listing is a nested tree. A backup tool wants a flat list of paths like 'src/app/main.py'.

Flatten a nested directory listing into path strings.

Requirements

  • Join names with the path separator the tests use.
  • Files (leaves) become full paths; directories continue the walk.

Constraints

  • tree: nested dict/list of names.
  • prefix: current path prefix.
  • Do not split existing names on extra slashes.

Examples

Input: flatten_dir({'a': {'b': None, 'c': None}, 'd': None}) Output: ['a/b', 'a/c', 'd'] This input follows the stated rules and produces this output.

Topics: lakebench, python, recursion.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Flatten a directory listing into paths

Interview-style drill: Given a nested dict representing folders and files, return every full file path.

Flatten a nested directory listing into path strings.