Morgan Stanley interview question

implementation of algorithms making some changes and with the result