FastPrepCount Balanced Bracket Insertions
Problems/Count Balanced Bracket Insertions

Count Balanced Bracket Insertions

Atlassian logoAtlassian● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Atlassian full-time online assessment. The report counts each insertion position as one way. We chose the function name and the limit for large inputs. Our version is about 99% the same as the reported question.

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) → int

Examples

Example 1

s = "()())"return = 5

The sequence has one extra closing bracket. Inserting an opening bracket at any of five valid positions produces a balanced sequence.

Constraints

  • 1 <= s.length <= 200000
  • s.length is odd.
  • s contains 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

Atlassian interview experiences

  • Atlassian MLE Phone Screen: Model Deployment Design: 1 Experience
  • Atlassian Coding Screens and Karat: 3 Experiences (Part 2 of 2)
  • Atlassian Full Stack Interviews: 11 Experiences (Part 1 of 2)
All Atlassian interview questionsSee Atlassian hiring insights
Saved
class Solution {
    public int countBalancedInsertions(String s) {
      // Write your code here.
    }

}
Checking account…