Generate Paranthesis

My code is not giving proper output.
Pls check and tell, how should I modify it ?

Ide : https://ide.codingblocks.com/s/192581

Hello @aman_ishan,

  1. open <= close
    Open will never be less than close. Otherwise, it will be an unbalanced parenthesis.

  2. Following will help in correcting the code:
    2.1. base case i.e. printing the balanced string of parenthesis
    when close == n
    2.2. insert a closing β€˜)’ parenthesis
    when open > close
    2.3. insert a opening β€˜(’ parenthesis
    when open < n

  3. the position of 2.2. and 2.3. will affect the order in which the balanced parenthesized will appear.
    Suggestion:
    Try to swap their positions to understand it better.

Hope, this would help.
Give a like if you are satisfied.

It’s generating only one kind of combination, not all possible variations. Pls check. IDE : https://ide.codingblocks.com/s/192645

Hey @aman_ishan,

This is because you have applied a wrong conditional check.
I have corrected your code:

Hope, this would help.

It passed all the test cases, but what condition will it go when open==close and open != n && close !=n. How is code handling this case.

Hello @aman_ishan,

These are conditions which is either not relevant to this question or will produce unbalanced string of parenthesis.
So, in these cases we are just returning from the function.

Hope, it is clear now.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.