Morgan Stanley interview question

Online coding challenge