Amazon Interview Question

Solve this problem in under 70 minutes