cheetcode

24. Generate ParenthesesMedium

Generate all combinations of well-formed parentheses for n pairs.

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.

The runner accepts any order as long as every valid combination appears exactly once.

Examples

Input: n = 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Input: n = 1
Output: ["()"]

Constraints

  • 1 <= n <= 8