A container-manifest is written as a string using only the six bracket characters (, ), [, ], {, and }. The string is guaranteed to be a valid, properly nested balanced bracket string: every opener has a matching closer of the same kind, and openers/closers nest correctly.
The nesting depth at any point is the number of brackets currently open. Report the maximum nesting depth reached anywhere in the string.
Line 1: the bracket string.
A single integer: the maximum nesting depth.
Example 1
Input
()
Expected
1
Explanation
One pair is open at its deepest, so the maximum nesting depth is 1.
Example 2
Input
([{}])Expected
3
Explanation
Opening (, then [, then { reaches three brackets open at once before any close, so the maximum depth is 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →