Amazon Interview Question

Two pointer question about how it works