Bloomberg Interview Question

Valid parenthesis and subway system