Amazon interview question

An algorithm question