Problem
You get an integer n. Return all the well formed strings that contain n pairs of parentheses.
A string of parentheses is well formed when each ( has a matching ) after it, and each ) has a matching ( before it. For example, "(())" is well formed, but "())(" is not.
You can return the strings in any order.
Example 1
- Input:
- n = 2
- Output:
- ["(())","()()"]
- Explanation:
- Two pairs give only two well formed strings.
Example 2
- Input:
- n = 4
- Output:
- ["(((())))","((()()))","((())())","((()))()","(()(()))","(()()())","(()())()","(())(())","(())()()","()((()))","()(()())","()(())()","()()(())","()()()()"]
- Explanation:
- Four pairs give 14 well formed strings.
Constraints
- 1 <= n <= 8
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Valid Parentheses
Coding · Bracket Sequences · Dynamic Programming · Stack
- Palindrome Partitioning
Coding · Backtracking · Dynamic Programming · String
- Valid Parenthesis String
Coding · Bracket Sequences · Dynamic Programming · Greedy
- Word Break II
Coding · Array · Backtracking · Dynamic Programming
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Microsoft
Leetcode 22. Generate Parentheses
Reported Jan 14, 2026 · 1 source report
JUNIOR
Source snapshot: Nov 12, 2026
View sourceSalesforce
Leetcode 22. Generate Parentheses
Reported Apr 25, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 5 records
Amazon
Generate Parentheses
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 72. This is not an interview probability.
View sourceAmazon
Generate Parentheses
Reported date not specified · Source window: 3mo