Yandex Interview Question

-How would you solve this problem?