Morgan Stanley interview question

Asked me array manipulation coding question,