Yandex interview question

algoritms tasks from leetcode