Pregunta de entrevista de Uber

Typical leetcode-style question solvable with an array