Amazon interview question

Typical algorithm complexity questions. Not difficult.