Revvity interview question

how to solve the valid parenthesis problem