Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given an integer ** 'N'**, your task is to generate all combinations of well-formed parenthesis having ‘N’ pairs.

A parenthesis is called well-formed if it is balanced i.e. each left parenthesis has a matching right parenthesis and the matched pairs are well nested.

For Example:

```
For ‘N’ = 3,
All possible combinations are:
((()))
(()())
(())()
()(())
()()()
```

Detailed explanation

```
2
```

```
()()
(())
```

```
There are two possible combinations of parentheses:
()()
(())
Here both the parenthesis are balanced so the possible outputs can be [ [ ()() ],[ (()) ] ].
```

```
4
```

```
()()()()
()()(())
()(())()
()(()())
()((()))
(())()()
(())(())
(()())()
(()()())
(()(()))
((()))()
((())())
((()()))
(((())))
```

```
1 <= 'N' <= 11
Time Limit: 1 sec.
```