Amazon interview question

Basic coding with follow up questions.