excess number of ('s within the prefix. For example, the string ()()() has nesting depth 1, but the string ((()))() has nesting depth 3, as we can see clearly if we count excess ('s for every prefix of the string: ((()))() 12321010 For the example farm above, the deepest string is ((())) with a depth of 3, and can be obtained by taking the path from A to B below: '('--'('--')'--'('--')' | | ')' ')'--'('--'(' &lt; A | | ')' '('--')'--')'--')'--'(' ^C ^B Note that this is different than the longest balanced s