Amazon interview question

Two pointer question about how it works