Morgan Stanley interview question

Étape 1 :Coding Game Brain teaser