Question not clear

Can you please explain this question?
What exactly do we have do?
Sample Testcase didnot help

hi @prasadnitesh202
See for input:
4 2
((

there are two opening brackets and according to question we have to balance the brackets by adding two string a and b such that size of overall new string formed is equal to given number n and at the same time we have to make sure that at every index of string opening brackets should be more than or equal to closing brackets. In above test case since size of final string given is 4 and size of original string given is 2 therefore we have to add two brackets more to satisfy above conditions and hence there is only one way possible that first string is empty and second one contains two closing brackets so that final string is “(())” .

And hence output is 1

For example if you are given s = “))” and n = 6(m = 2 obviously) then you can generate following pairs of a and b to make a+s+b a valid sequence:

“()((” “))” “” // Remember a and b can be blank also.
“((” “))” “()”
“(((” “))” “)”
“(()(” “))” “”
“((()” “))” “”

Hence, the ans for this testcase is 5. If there is no possible combination then print -1.

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.