Binance interview question

Solve a medium LC question