← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Meta/Leetcode 1541. Minimum Insertions to Balance a Parentheses String
CodingMust
You are given a string containing only the characters '(' and ')'. However, in this problem, the parentheses follow a special balancing rule: each opening bracket '(' must be closed by exactly two consecutive closing brackets '))'.
Your task is to find the minimum number of bracket insertions (either '(' or ')') needed at any position in the string to make it balanced according to this rule.
A balanced string under this rule means:
'(' has exactly two ')' following it (not necessarily immediately)'))' has a matching '(' before it'(' and ')' characters are present in the inputs.length ≤ 100,000s consists only of '(' and ')'Example 1:
` Input: s = "(()))" Output: 1 Explanation:
Example 2:
` Input: s = "())" Output: 1 Explanation:
Example 3:
` Input: s = "))())(" Output: 3 Explanation:
Example 4:
` Input: s = "(((" Output: 6 Explanation: