Practice Minimum Insertions to Balance a Parentheses String
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Treat ( as an opening token and two consecutive characters )) as one closing token. Every opening must match a later closing token in a properly nested sequence. Insert individual ( or ) characters anywhere in s and return the minimum number of inserted characters needed to balance it.
Source: Minimum Insertions to Balance a Parentheses String on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "(()))"
1
# Example 2
s = "())"
0
# Example 3
s = "))())("3
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Insertions to Balance a Parentheses String.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.