Count Balanced Bracket Insertions
Updated
Problem 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 Online Assessment questions
- 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
- Binary Search Tree IteratorOA · Seen Nov 2023
- Binary Tree Level Order TraversalOA · Seen Nov 2023
Similar questions at other companies
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
- Maximum Equalized Substrings After One Adjacent SwapVisa · OAVisa interview questions
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Balanced Split String with WildcardsTwo Sigma · OATwo Sigma interview questions
- Longest Balanced Substring After One SwapTekion · OATekion interview questions
- Shortest Compressed Length After RemovalDRW · OADRW interview questions
- Count Special StringsAmazon · OA
- Binary Palindromic Subsequences of Length 5Citadel · OACitadel interview questions