Pregunta de entrevista de Amazon

Some array question (leetcode medium difficulty)