all test cases wrong…although full code is correct !!!
Generate parenthesis
Hey @hg11110000
if (open > close) //place this if block before other if block
{
out[idx] = ')';
f(out, n, idx + 1, open, close + 1);
}
if (open < n)
{
out[idx] = '(';
f(out, n, idx + 1, open + 1, close);
}
If this resolves your query then please mark it as resolved
why so ??
although generates same output ??
and that too sorted as expected
No output differ in both the cases
And the change I suggested was implemented in backend ,hence to match output line by line we just swapped the blocks,.
Ur code is correct, just output order is different in both the cases.
Check for sample input
same only
()()
(())
for 3 also i guess it will come same
()()()
()(())
(())()
(()())
((()))
where the difference is coming ? @
For 2 ur ouptut is this
(())
()()
For 3 ur output is this
((()))
(()())
(())()
()(())
()()()