Maximum Nesting Depth of the Parentheses
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a string s that is a valid arithmetic-style expression: it contains digits, the operators + - * /, and parentheses ( ) that are correctly balanced and properly nested.
The **nesting depth** of a position is the number of parentheses that are open around it. Return the maximum nesting depth over the whole string, i.e. the largest number of parentheses that are simultaneously open at any point. A string without parentheses has depth 0.
Aim for O(n) time and O(1) extra space.
Examples
Constraints
- 1 <= s.length <= 100
- `s` consists of digits `0-9` and the characters `+ - * / ( )`.
- The parentheses in `s` are balanced and properly nested.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.