Amazon interview question

Array related problem. easily found in previous question papers.