TSS Consultancy interview question

Code based on parentheses matching.