Generate Parentheses
Given n pairs of parentheses, generate all combinations of well-formed (valid) parentheses strings of length 2n. Every open bracket must be matched by a later close bracket.
Open official problem prompt ↗Produce every balanced parentheses string that uses exactly n opening and n closing brackets.
Stacking and unstacking plates: you can only place a plate down (open) if you have plates left, and you can only remove one (close) if the stack is non-empty; every valid sequence of moves is one answer.
- Input
- n = 3
- Output
- ["((()))","(()())","(())()","()(())","()()()"]
- Why
- These are exactly the 5 balanced strings using 3 '(' and 3 ')'; the count is the 3rd Catalan number, C(3) = 5.
1 <= n <= 8