Pergunta de entrevista da empresa YANDEX

got task to solve with two pointers