Pergunta de entrevista da empresa Yandex

Some leetcode task, which wasn't hard