Amazon interview question

Leetcode Medium question on Arrays