Example - n = 3
Input
3
Output
['((()))', '(()())', '(())()', '()(())', '()()()']
All 5 valid combinations for 3 pairs.
Full lesson preview
Produce all combinations of n pairs of well-formed parentheses using recursion and backtracking.
Problem statement
Task
Examples
Input
3
Output
['((()))', '(()())', '(())()', '()(())', '()()()']
All 5 valid combinations for 3 pairs.
Input format
Output format
Constraints
Samples
Input
2
Output
['(())', '()()']
Two valid combinations for 2 pairs.