37. How do you sort a file that is too large for memory?
HardSorting
Technical
Show model answer
External merge sort: read chunks that fit in memory, sort each and write it out as a sorted run, then perform a k-way merge of the runs using a min-heap that holds the current head of each run. Choose chunk sizes and the merge fan-in to minimise disk passes.