Bloomberg Interview Question

I was asked medium leetcode similar to parentheses matching problem.