Given a valid parentheses string s, return the nesting depth of s. The nesting depth is the maximum number of nested parentheses. A string is a valid parentheses string (denoted VPS) if it meets one of the following: 1. It is an empty string "", or a single character not equal to '(' or ')', such as a digit or an operator. 2. It can be written as AB (A concatenated with B), where A and B are VPS's. 3. It can be written as (A), where A is a VPS. The nesting depth depth(S) of a VPS S is defined as: - depth("") = 0 - depth(C) = 0, where C is a single character that is not a parenthesis - depth(A + B) = max(depth(A), depth(B)) - depth("(" + A + ")") = 1 + depth(A)
Example 1
Input: s = (1+(2*3)+((8)/4))+1
Output: 3
Explanation: Digit 8 sits inside three nested parentheses, so the maximum nesting depth is 3.
Example 2
Input: s = (1)+((2))+(((3)))
Output: 3
Explanation: The deepest group (((3))) nests three levels.
Example 3
Input: s = ()(())((()()))
Output: 3
Explanation: The final group reaches depth 3.
Every '(' opens one more level of nesting and every ')' closes one. The nesting depth at any point is simply how many parentheses are currently open, so a single counter that goes up on '(' and down on ')' tracks the live depth. The answer is the highest value that counter ever reaches.
Run checks all cases above. Submit evaluates all test cases.