Amazon Interview Question

Classical parentheses balancing problem