Sollicitatievraag bij J.P. Morgan

How did you solve your coding problem and explain it?