Amazon interview question

The most difficult part was the most efficient algorithm