Yandex Interview Question

some tasks from leet code