Generate all parenthesis

Hard
0/120
Average time to solve is 45m
13 upvotes
Asked in company
Cerner Corporation

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 set of parenthesis that can be formed with given number of pairs.

Detailed explanation ( Input/output format, Notes, Images )
Input format :
Integer n
Output format :
Print all possible valid parenthesis in different lines

Note: Order in which different combinations of well-formed parentheses are printed in different lines doesn't matter.

Constraints :

1 <= n <= 10

Sample Input :
3
Sample Output :
((()))
(()())
(())()
()(())
()()()
Generate all parenthesis
Full screen
Console