Pregunta de entrevista de Yandex

2 tasks looks like leetcode easy-medium.