J.P. Morgan Interview Question

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