Amazon interview question

Show me how to code this coding problem.