Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Example 1
Input: n = 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Explanation: With 3 pairs, a string is valid when no prefix has more ')' than '('. Exactly five strings satisfy this: ((())), (()()), (())(), ()(()) and ()()().
Example 2
Input: n = 1
Output: ["()"]
Explanation: With one pair, the only valid string is "()".
Example 3
Input: n = 2
Output: ["(())","()()"]
Explanation: With two pairs, the valid strings are "(())" (nested) and "()()" (side by side).
Build the string one bracket at a time, tracking how many '(' and ')' have been used. You may add '(' while some opens remain, and ')' only while there are unmatched opens — this guarantees every generated string is valid.
Run checks all cases above. Submit evaluates all test cases.