Pregunta de entrevista de Yandex

For all questions related to algorithms their complexity must be calculated