BlackRock Interview Question

valid parenthesis and graph problem