FastPrepBalanced Brackets in an Expression
Problems/Balanced Brackets in an Expression

Balanced Brackets in an Expression

Bank of America logoBank of America● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by three Bank of America new grads from campus hiring drives, as one of two coding tasks in a recorded video interview; a later video answer in the same step asked them to explain how they solved it. The task was to decide whether the brackets of an expression open and close in the right order. One report names a stack as the tool.

The reports give no examples of their own or limits. Here, the expression mixes round, square and curly brackets with letters, digits, spaces and arithmetic signs, and has at most 10,000 characters.

Our version is about 95% the same as the reported question.

Given a string expression, return true if its brackets are balanced and false otherwise.

The expression can use three kinds of brackets: round ( ), square [ ] and curly { }. The brackets are balanced when every opening bracket is later closed by a closing bracket of the same kind, every closing bracket closes an earlier opening bracket, and a pair that opens inside another pair also closes inside it. All other characters are ignored, so an expression with no brackets is balanced.

Function

isBalanced(expression: String) → boolean

Examples

Example 1

expression = "{a+(b*c)}-[d]"return = true

( opens inside { and closes before it. Then [ opens and closes. Every bracket has a partner of the same kind.

Example 2

expression = "(x+y]*2"return = false

The round bracket ( is closed by a square bracket ], which is the wrong kind.

Example 3

expression = "[(m)]-(n"return = false

The first part [(m)] is fine, but the last ( is never closed.

Constraints

  • 1 <= expression.length <= 10^4
  • expression consists of lowercase English letters, digits, spaces, the brackets ( ) [ ] { } and the signs + - * /

More Bank of America Online Assessment questions

  • Return Exact Cash Register ChangeOA · Seen Aug 2026
  • Sum Skipping Multiples of 7OA · Seen Nov 2025
  • Wildcard Substring MatchOA · Seen Nov 2025
  • Maximum String BeautyOA · Seen Sep 2024
  • Merge Point of Two Linked ListsOA · Seen Oct 2023
  • Remove Duplicates from a ListOA · Seen Oct 2023
  • Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
  • Count Level-Order Traversals of a TreeOA · Seen Sep 2023
  • Count Set BitsOA · Seen Sep 2023
  • Count Pairs with Sum KOA · Seen Jun 2023

Similar questions at other companies

  • Validate a Bracket SequenceInMobi · OAInMobi interview questions
  • Valid ParenthesesBlackRock · OABlackRock interview questions
  • Valid ParenthesesVanguard · OAVanguard interview questions
  • Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
  • Get Final StringIBM · OAIBM interview questions
  • Backspace String CompareGoldman Sachs · OAGoldman Sachs interview questions
  • The PromHackerEarth · OA
  • Compare Character Arrays with BackspacesOdoo · OAOdoo interview questions
  • Eliminate SubstringJP Morgan Chase · OAJP Morgan Chase interview questions
  • Balancing ParenthesesOracle · OAOracle interview questions

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights
Saved
class Solution {
    public boolean isBalanced(String expression) {
        // write your code here
    }
}
Checking account…