Tap here to switch tabs
Problem
Submissions

Problem: Minimum Insertions to Balance a Parentheses String

med
30 min
Try to solve the Minimum Insertions to Balance a Parentheses String problem.

Statement

Given a parentheses string s containing only the characters '(' and ')'.

A parentheses string is considered balanced when:

  • Every open parenthesis '(' is matched with exactly 22 consecutive closing parentheses '))'.

  • Every open parenthesis '(' occurs prior to its corresponding pair of closing parentheses '))'.

You may insert characters '(' or ')' at any position within the string.

Return the minimum number of insertions required to make s balanced.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists of '(' and ')' only.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Insertions to Balance a Parentheses String

med
30 min
Try to solve the Minimum Insertions to Balance a Parentheses String problem.

Statement

Given a parentheses string s containing only the characters '(' and ')'.

A parentheses string is considered balanced when:

  • Every open parenthesis '(' is matched with exactly 22 consecutive closing parentheses '))'.

  • Every open parenthesis '(' occurs prior to its corresponding pair of closing parentheses '))'.

You may insert characters '(' or ')' at any position within the string.

Return the minimum number of insertions required to make s balanced.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • s consists of '(' and ')' only.