Amazon interview question

Got a Stack coding problem