Splunk Interview Question

Some kind of array manipulation using 2 pointers for efficiency, can be solved in n^2 trivially