Problem · String
Count Balanced Bracket Insertions
Learn this problemProblem statement
Given an odd-length string s containing only parentheses, insert exactly one '(' or ')' at any of the s.length + 1 positions.
Count the insertion choices that make the resulting sequence balanced. Choices are counted by insertion position, even when two positions produce the same final text.
Function
countBalancedInsertions(s: String) → intExamples
Example 1
s = "()())"return = 5The sequence has one extra closing bracket. Inserting an opening bracket at any of five valid positions produces a balanced sequence.
Constraints
1 <= s.length <= 200000s.lengthis odd.scontains only(and).
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024