Amazon Interview Question

Array related problem. easily found in previous question papers.