formula whose brackets are properly matched: every opening bracket has its own closing one, and no closing bracket comes before its opening partner.
The depth of a character is the number of bracket pairs that enclose it at once. Return the greatest depth reached anywhere in the formula. If there are no brackets, the answer is 0.formula="(x-(4*y))/((2+(z)))" → 3
The letter z sits inside three pairs of brackets: ((2+(z))). Nothing goes deeper.
formula="7+a*b" → 0
There are no brackets at all, so the depth is 0.
formula="()(())()" → 2
The deepest point is inside (()), two levels down.
formula consists of digits, lowercase English letters, the signs +, -, *, / and the brackets (, )formula are properly matchedformula="(x-(4*y))/((2+(z)))"
3
Run checks the first 3 tests in your browser. Submit checks all 67 tests on the server, hidden ones included.