Amazon interview question

Do not remember properly based on the array