Optiver interview question

Leet code hard from list