Amazon Interview Question

A DSA question based on stacks