J.P. Morgan interview question

two codings and then talk about your code and improvement.