BlackRock interview question

valid parenthesis and graph problem