Amazon interview question

Stack question leet code easy