Yandex interview question

To solve an algo problem