Why I am not getting any output?
Generate parenthesis
change ur n to 2*n
and limit to n
generateParenthesis(2*n,"",0,n,0);
hope this will heip u
pls help me by rating my work
There are few mistakes in your code,
- since both left and right parenthesis would make up the string so the 2*n should be passed in generateParenthesis()
- condition when the no of right parenthesis become more than left ones has to be set
- call in addition of β(β braces first for the recursion to work properly.
- limit variable has to be initially n since max left braces can be n
try to work out on these suggestions.
-
in the qn, we have to generate all the possible pairs of n balanced parentheses.
so i have passed the total length as 2n. -
close brackt canβt be greater than the open bracket
becoz β)β is appending only when it is less than β(β -
recursion r working fine
firstly always open bracket will make call then close bracket will make call becoz of the condition open<close -
as we have to generate using n pairs
so no of left bracket == n
hope this will help u
pls rate my work