Pergunta de entrevista da empresa Optiver

2 rather difficult programming questions since the amount of time given was 2 hours for both.