Morgan Stanley Interview Question

Online coding challenge