YANDEX Interview Question

got task to solve with two pointers