Morgan Stanley Interview Question

A leetcode question under array topic.