J.P. Morgan interview question

How could you improve your code and go through the thought process