Optiver Interview Question

HackerRank test, given 48 hours