Deepest Nested Substrings
Problem statement
Given a balanced string containing lowercase letters and the bracket pairs (), [], and {}, return the contents of every bracket pair at the maximum nesting depth.
Return results from left to right. The returned content excludes the surrounding brackets. An empty deepest pair contributes the empty string.
Function
deepestNestedSubstrings(expression: String) → String[]Examples
Example 1
expression = "a[bc]def{cd}"return = ["bc","cd"]Both pairs are at depth one, the maximum depth.
Example 2
expression = "ran(n(d))o(m())"return = ["d",""]The pairs around d and the empty string are the depth-two pairs.
Example 3
expression = "x{a[b(c)d]e}y"return = ["c"]The innermost parentheses are at depth three.
Constraints
0 <= expression.length <= 10^5.- The expression contains lowercase English letters and balanced, correctly matched brackets.