J.P. Morgan Interview Question

How did you solve your coding problem and explain it?