Amazon interview question

Typical programming problems.