Write a function generateParentheses(n)
that returns all combinations of well-formed parentheses for a given number of pairs n
. You must implement your solution using a recursive approach.
generateParentheses(n)
where n
is the number of pairs of parentheses.For n = 3
, one possible output is:
["((()))", "(()())", "(())()", "()(())", "()()()"]
In celebration of the upcoming summer and the balance between work and leisure, enjoy this recursive challenge to balance your code as well!