#K92137. Maximum Parentheses Nesting Depth
Maximum Parentheses Nesting Depth
Maximum Parentheses Nesting Depth
You are given a string s
consisting of characters, including parentheses. Your task is to compute the maximum depth of nested parentheses in the string.
The depth is defined as the maximum number of open parentheses that exist at any point in the string. For example, the string (())
has a depth of 2, and the string ((()))
has a depth of 3.
Please note that the input string may contain other characters, but only the parentheses ('(' and ')')
are used to determine the depth.
Mathematically, if we denote the depth at any position as d_i
, then the maximum depth is given by \(\max_{i} d_i\), where \(d_i\) is incremented by 1 for every '(' encountered and decremented by 1 for every ')' encountered.
inputFormat
The input is provided via standard input (stdin) as a single line containing the string s
(which may include spaces and other characters).
outputFormat
Output the maximum nested depth of parentheses as an integer to standard output (stdout).
## sample()
1