Amazon Interview Question

How would you walk through this problem