Pregunta de entrevista de Google

solving with two pointer question