Morgan Stanley Interview Question

implementation of algorithms making some changes and with the result