Pregunta de entrevista de Google

It was a coding exercise.