Pregunta de entrevista de Amazon

Easy alghoritmic programming question to solve