Generate Parentheses

Advanced

Let's dive into the world of parentheses! Have you ever wondered how many ways you can properly nest parentheses? In this challenge, your task is to write a function that generates all combinations of well-formed parentheses.

Given a positive integer n, your function should return all combinations of n pairs of parentheses.

Your mission is to create the function generate_parentheses that takes an integer n and returns these combinations in a list.

Here are some examples to help you understand:

# Example 1: # For n = 1, we can only form one pair: # The function returns: ['()'] generate_parentheses(1) # Example 2: # For n = 2, there are two pairs possible: # The function returns: ['(())', '()()'] generate_parentheses(2) # Example 3: # For n = 3, the combinations are more: # The function returns: ['((()))', '(()())', '(())()', '()(())', '()()()'] generate_parentheses(3)

Remember, the goal is to generate only valid combinations where each opening parenthesis has a corresponding closing parenthesis. Have fun exploring the different patterns you can create!

Geek
Inputs

Arg 1:

1
Expected Output
["()"]
Actual Output