Amazon interview question

Two coding questions, one easy, second medium