Mobile coding works. A laptop is faster for long sessions.
Problem
The program reads from standard input a line containing an expression. Only round parentheses `(` and `)` are of interest; all other characters are ignored.
The depth of a parenthesis is the number of open parentheses that contain it, including itself. Print the maximum depth reached in the expression.
It is guaranteed that the parentheses are correctly matched (every `(` has a matching `)` and no `)` appears before its corresponding open parenthesis).
Input format
Input
input.txt
The program reads from standard input a single line with the expression (at most 1000 characters long).
Output format
Output
output.txt
The program prints to standard output a single non-negative integer: the maximum nesting depth of the parentheses. If no parentheses appear in the expression, print `0`.
Example
input
((a+b)*(c-(d+e)))
output
3
Stuck?
Use the Get Hint button in the action bar to reveal a guided hint.
💬 Discussion
Loading...💬
No comments yet. Be the first to start the discussion!
💻 No output yet.
Click Run in the editor to execute your code with the custom input.
Sample cases (from the problem)
Sample Case 1
Input
((a+b)*(c-(d+e)))
Expected output
3
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.
⌨️ Keyboard Shortcuts
Code Editor
Run Code
Ctrl
Enter
Submit Code
Ctrl
Shift
Enter
Format Code
Shift
Alt
F
Toggle Comment
Ctrl
/
Undo
Ctrl
Z
Redo
Ctrl
Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc