Close
Topic list
Generate all parenthesis
MEDIUM
30 mins
Strings
Topics (Covered in this problem)
Problem solved
Skill meter
Strings
-
-
Other topics
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
-
-
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
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 all parenthesis

Contributed by
Arindam Majumder
Medium
0/80
Avg time to solve 30 mins
Success Rate 85 %
Share

## Problem Statement

#### For Example:

``````For ‘N’ = 3,
All possible combinations are:
((()))
(()())
(())()
()(())
()()()
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
``````
##### Sample Output 1:
``````()()
(())
``````
##### Explanation For Sample Output 1:
``````There are two possible combinations of parentheses:
()()
(())
Here both the parenthesis are balanced so the possible outputs can be [ [ ()() ],[ (()) ] ].
``````
##### Sample Input 2:
``````4
``````
##### Sample Output 2:
``````()()()()
()()(())
()(())()
()(()())
()((()))
(())()()
(())(())
(()())()
(()()())
(()(()))
((()))()
((())())
((()()))
(((())))
``````
Auto
Console