Amazon Interview Question

Solve a coding question based on Stacks