Optiver Interview Question

Leet code hard from list