Amazon Interview Question

valid parenthesis question for part 2