Balanced brackets up to a depth
Return every string of n pairs of round brackets that is balanced and never nests deeper than max_depth. Balanced means each ( is closed by a later ), and reading left to right never shows more ) than ( so far. A string's depth is the most brackets open at once: "(())()" has depth 2, "()()()" depth 1. Return each string once, in any order; for n = 0 the only answer is the empty string.
0 ≤ n ≤ 11, 1 ≤ max_depth ≤ 11.
Besides the tests, one large input (11 pairs, depth at most 2) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
balanced_strings(3, 3)→["((()))","(()())","(())()","()(())","()()()"]balanced_strings(3, 1)→["()()()"]balanced_strings(3, 2)→["(()())","(())()","()(())","()()()"]