FastPrepMaximum Nesting Depth of Parentheses
Problems/Maximum Nesting Depth of Parentheses

Maximum Nesting Depth of Parentheses

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names this well-known problem directly in a Bloomberg new-grad virtual onsite. We state the usual meaning of depth (the most open parentheses at one time), the function signature, the examples and the input limits.

Given a string expression whose parentheses are balanced, return the maximum number of simultaneously open parentheses at any position.

Characters other than ( and ) do not affect the depth.

Function

maxDepth(expression: String) → int

Examples

Example 1

expression = "(1+(2*3)+((8)/4))+1"return = 3

The innermost parentheses around 8 are nested inside two other open pairs.

Example 2

expression = "(1)+((2))+(((3)))"return = 3

The final term opens three parenthesis pairs before closing any of them.

Example 3

expression = "1+2"return = 0

The expression contains no parentheses.

Constraints

  • 1 <= expression.length <= 100000
  • expression contains printable ASCII characters.
  • The parentheses in expression are balanced.

More Bloomberg LP Onsite Interview questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • English to Morse CodeOscar Health · PHONE SCREEN
  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • String CompressionShnoor International · ONSITE INTERVIEW
  • Extract Hashtags from a TweeteBay · ONSITE INTERVIEWeBay interview questions
  • Run-Length Encoding and DecodingAirbnb · PHONE SCREENAirbnb interview questions
  • Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
  • Christmas Tree with N TiersVerily · ONSITE INTERVIEW
  • Straight-Line Word SearchReddit · PHONE SCREENReddit interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions

Interview reports that mention this question

  • Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
  • Bloomberg New Grad SWE Offer Loops: 14 Experiences (Part 2 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int maxDepth(String expression) {
        // Write your code here.
    }

}
Checking account…