Wrong on all test cases

even though code is working,it is showing wrong on all the test cases. Does the order of combinations also matter?
if so, how to fix it?

Hi Shivam,
Request you to share the code through the Coding Blocks IDE (cb.lk/ide). It would be a lot easier for me to help you if you could share your code through the mentioned platform.
Just paste the code at cb.lk/ide, save it, and share the generated URL.
Also, keep in mind this line from the problem statement when printing the output : β€œThe output strings should be printed in the sorted order considering β€˜(’ has higher value than β€˜)’.”

The error is definitely in the order of the output. e.g. For n=2,
Actual:
()()
(())
Yours:
(())
()()

The order of the output is reversed. Remember this printing criterion:
β€œThe output strings should be printed in the sorted order considering β€˜(’ has higher value than β€˜)’.”
i.e. ) < ( when sorted.

The naive approach is to store all the output strings in a separate list and then sort according to the above condition.
The smart approach is to just reverse the order of the recursive calls which would result in implicitly sorted output.

Hope this helps!