Amazon interview question

Solve a coding question based on Stacks