
May 18, 2012. Facebook goes public and Nasdaq's opening cross keeps restarting, because orders keep arriving while it recalculates. The book it was matching against was already stale by the time it finished. Trading opens half an hour late. Confirmations vanish for hours, and market makers eat around 500 million dollars. The book has to stay sorted at every single insertion, not once at the end.
Objective
Insert a bid into a book sorted from the highest price down, and report where it landed.
Steps
$ insert_order({90,70,50}, 3, 80)
book 90 80 70 50, returns 1
$ insert_order({90,70,50}, 3, 90)
book 90 90 70 50, returns 1
$ insert_order({}, 0, 42)
book 42, returns 0
Expected files
Allowed functions
None. Write every helper yourself.
Loading solutions...