J.P. Morgan interview question

How did you solve your coding problem and explain it?