Maximum Nesting Depth of Parentheses
Advanced String Algorithms DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Maximum Nesting Depth of Parenthesis, Strings, Loops, Conditional Statements, Time Complexity, Space Complexity, Big O Notation, counting, expression parsing, stack, string traversal, time complexity analysis, Parentheses Parsing.
Maximum Nesting Depth of Parentheses A string is a Valid Parentheses String (VPS) if it meets one of the following conditions: It is an empty string "". It contains a single character that is not ( or ). It can be written as AB (concatenation of A and B), where A and B are VPS's. It can be written as (A), where A is a VPS. The nesting depth of a VPS s is defined as follows: depth("") = 0 depth(c) = 0 for any character c that is not ( or ). depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's. depth("(" + A + ")") = 1 + depth(A), where A is a VPS. Given a Valid Parentheses String s, return its maximum nesting depth. Input A single line containing the string s. Output A single integer representing the maximum nesting depth. Constraints 1 <= s.length <= 100 s consists of digits (0 9), +, , , /, (, and ). It is guaranteed that s is a Valid Parentheses String . Sample Test Cases Sample Input 1: Sample Output 1: Sample Input 2: Sample Output 2: Sample Input 3: Sample Output 3: