Yandex interview question

some tasks from leet code