Amazon Interview Question

leetcode easy question: stack problem