Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Generate Parentheses
EASY
10 mins
9 upvotes
Strings
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Strings
-
-
Other topics
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Generate Parentheses

Contributed by
Arshit Babariya
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
9 upvotes

Problem Statement

Given N pairs of parentheses, write a function to generate and print all combinations of well-formed parentheses. That is, you need to generate all possible valid sets of parentheses that can be formed with a given number of pairs.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
3
Sample Output 1:
{{{}}}
{{}{}}
{{}}{}
{}{{}}
{}{}{}
Explanation For Sample Input 1:
These are the only five sequences of balanced parentheses formed using 3 pairs of balanced parentheses.
Sample Input 2:
2
Sample Output 2:
{{}}
{}{}
Reset Code
Full screen
Auto
copy-code
Console