Pregunta de entrevista de Revvity

how to solve the valid parenthesis problem