Amazon interview question

A few coding problems, moderate difficulty.