Amazon interview question

valid parenthesis question for part 2