Back to problems

Minimum Add to Make Parentheses Valid II

Algorithm · Meta · Medium

Requirements Given a string s made up exclusively of ( and ), determine the smallest number of parentheses that must be inserted so the resulting string is properly balanced: each opening parenthesis must pair with a closing parenthesis, and each closing parenthesis must pair with an opening parenthesis. Implement the following function: Return the minimum insertion count as an integer. Examples Example 1 Input: Output: Explanation: Adding one ( before the final ) produces…

Checking your access…