Qualcomm interview question

Valid parenthesis Q from leetcode.