Pergunta de entrevista da empresa Amazon

Typical algorithm complexity questions. Not difficult.