Yandex Interview Question

For all questions related to algorithms their complexity must be calculated