Bottomline Interview Question

How to solve the matching parentheses Leetcode problem