
August 14, 2003. A control room in Ohio runs alarm software with a hidden race condition. Two processes reach for the same alarm queue at once, the alarm system stalls, and the operators stop seeing warnings just as power lines start to fail. Nobody reacts in time, and the cascade takes down the grid for 55 million people across the northeast US and Ontario, some of them for two days. The fix the racy code could never manage: merge the event streams in order, the same way every time. Do that.
Objective
Merge two already sorted alarm streams into one sorted stream, deterministically.
Steps
$ merge_alarms(out, {1,3,5}, 3, {2,4}, 2)
1 2 3 4 5
$ merge_alarms(out, {2,2}, 2, {2}, 1)
2 2 2
Expected files
Allowed functions
None. Write every helper yourself.
Loading solutions...