Generate Parentheses
Description
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
A well-formed parentheses string must have every opening parenthesis ( matched with a closing parenthesis ) in the correct order.
Example 1
Input
n = 3
Output
["((()))","(()())","(())()","()(())","()()()"]
Explanation
There are five different combinations of three pairs of well-formed parentheses.
Example 2
Input
n = 1
Output
["()"]
Explanation
With one pair of parentheses, there is only one valid combination.
Constraints
Hints:
Hint 1
At any point, you can add ( as long as you still have opening parentheses available.
Hint 2
You can add ) only when the number of closing parentheses used is less than the number of opening parentheses used.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 10, 2026
Last updated
Aug 10, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output