Revvity Interview Question

how to solve the valid parenthesis problem