Amazon interview question

A DSA question based on stacks