Tap here to switch tabs
Problem
Submissions

Problem: Minimum Insertions to Balance a Parentheses String

Minimum Insertions to Balance a Parentheses String asks you to add the fewest opening or closing parentheses so every opening parenthesis has two consecutive closing parentheses.

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

Minimum Insertions to Balance a Parentheses String asks you to add the fewest opening or closing parentheses so every opening parenthesis has two consecutive closing parentheses.

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.