Flat Memory
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- mid
Problem
An external sort spills sorted runs to disk, then folds them back a pair at a time to keep memory flat. Each `primary` buffer keeps its own `filled` values in order at the front and reserves exactly enough zeroed slots at the tail to absorb the `incoming` run, which is itself already sorted. Combine the two into one ascending sequence using only the room `primary` already holds, and return that buffer. An empty `incoming` leaves the buffer unchanged.
Summary
Two sorted runs, one buffer, no scratch space. Fold them together where they already live.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.