Amazon interview question

usual coding problems from cracking the code interview