Salesforce interview question

Leetcode medium question involving parenthesis