Yandex Interview Question

Some leetcode task, which wasn't hard