Amazon Interview Question

Any other ways to do this problem, and why and how