Generate Parentheses
Return all valid parentheses combinations for n pairs.
Examples
Input: 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Input: 1
Output: ["()"]
Hints
Use backtracking to explore all possible combinations, pruning invalid paths early.
Maintain a balance counter: increment for '(', decrement for ')'. Only proceed if balance ≥ 0.
Optimize by preallocating a character array of size 2n and modifying it in-place to avoid string concatenation overhead.
Related Problems
Generate Parentheses
Return all valid parentheses combinations for n pairs.