Amazon Interview Question

The most difficult part was the most efficient algorithm