Google Interview Question

solving with two pointer question