Amazon Interview Question

Some array question (leetcode medium difficulty)