Last Updated: 21 Oct, 2016

Generate all parenthesis

Hard
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.

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