J.P. Morgan Interview Question

two codings and then talk about your code and improvement.