Pregunta de entrevista de Yandex

-How would you solve this problem?