Zero To DSAZero To DSA
Privacy Policy
Combination SumN-Queens

Generate Parentheses

medium
Time: O(4ⁿ / √n)
Space: O(n)

Given n pairs of parentheses, generate all combinations of well-formed parentheses.

Constraints

  • 1 <= n <= 8

Examples

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