Merge K sorted trade logs with a heap
Asked at Jump Trading, Citadel
Each of your exchange gateways writes a log already sorted by timestamp. You need one globally sorted stream for replay.
logs = [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
merge_sorted(logs) -> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Merge the sorted lists into one sorted list. Do better than concatenating and re-sorting. What is the cost?
Show a hint
At any moment the next output value is the smallest among the current fronts of the lists, only candidates, not . What structure hands you the minimum of things and lets you replace it cheaply?
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.