Verified interview challenge
Flatten and rebuild nested structures
Traverse nested containers in a precise order, then reconstruct their structure from a flat sequence.
Unlock with Full AccessThe challenge
Lists, tuples and dictionaries can be mixed throughout the input. The first part collects their integer leaves, and the second rebuilds the same shape with new leaf values. Preserve container types, positions and ordering, including empty containers, while handling deep inputs without relying on Python's recursion limit.
What you'll practise
Traversal consistency
Use the same encounter order in both directions without modifying inputs.
Shape preservation
Retain the distinction between leaves, keys and empty container structure.
# Build on your implementation
# Run checks for the current part
# Full starter code includedRun your code to see results.