Top Hat interview question

The Valid Parenthesis Question from Leetcode