Pregunta de entrevista de Point72

Easy hackerrank question made harder by requiring linear time complexity