Pregunta de entrevista de J.P. Morgan

How did you solve your coding problem and explain it?