Amazon interview question

Cannot really discuss these problems.