Amazon interview question

Both coding questions were easy