598. Maximum Nesting Depth of Parentheses

EasyStackStackString

Given a string s (a valid expression that may contain digits, operators, and parentheses), return the maximum nesting depth of the parentheses. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the maximum nesting depth.

Examples

Example 1
Input: {"s":"(1+(2*3)+((8)/4))+1"}
Output: 3
Explanation: The deepest nesting is 3.
Example 2
Input: {"s":"1+(2*3)/(2-1)"}
Output: 1
Explanation: No nesting beyond one.
Example 3
Input: {"s":"1"}
Output: 0
Explanation: No parentheses.

Constraints

Asked by

BloombergMetaAmazonGoogleMicrosoft
Solve this problem in the editor →