Amazon Interview Question

Got a Stack coding problem