← ALL NOTES
String

1614. Maximum Nesting Depth of the Parentheses

The tag on this one says Stack, and that is the trap. A stack exists to remember which ( a ) closes, but nothing in the question ever asks about a pair. It asks how many parentheses were open at the deepest moment of the string, and a single counter already carries that number.

Loading…