Trains the technique from
LeetCode 1614Maximum Nesting Depth of the ParenthesesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A control panel writes each logged formula as a string line built from the digits 0 to 9 and the characters +, -, *, /, ( and ).
The brackets in line always pair up: reading left to right, a ) never appears before its partner, and every ( is closed before the line ends. The panel makes no promise about the arithmetic itself, so apart from the brackets a line may read oddly.
Every bracket pair in line sits inside some number of other bracket pairs. Call one more than that number the pair's layer, so a pair nested inside nothing is on layer 1.
Return the largest layer reached by any bracket pair in line, and 0 when line has no brackets at all.
Example 1
The outer pair wrapping `(5-2)*3` sits inside nothing, so it is on layer 1, and the pair around `5-2` sits inside it on layer 2.
Example 2
No brackets appear anywhere in the line.
Example 3
The pair around `9` sits inside one other pair, putting it on layer 2. The pair around `8` sits inside nothing, so it is only on layer 1.
Example 4
The pair around `5` sits inside the pair around `4+(5)`, which sits inside the outermost pair, so that innermost pair is on layer 3. The pair around `3` reaches only layer 2.
Example 5
One pair, sitting inside nothing, so its layer is 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_depth(line: str) -> int:public int maxDepth(String line)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.