Maximum Nesting Depth of Parentheses
Updated
Problem statement
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) → intExamples
Example 1
expression = "(1+(2*3)+((8)/4))+1"return = 3The innermost parentheses around 8 are nested inside two other open pairs.
Example 2
expression = "(1)+((2))+(((3)))"return = 3The final term opens three parenthesis pairs before closing any of them.
Example 3
expression = "1+2"return = 0The expression contains no parentheses.
Constraints
1 <= expression.length <= 100000expressioncontains printable ASCII characters.- The parentheses in
expressionare 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