About the Problem

If the total number of brackets should be equal in the string, then how is it possible that at each index the number of opening brackets are greater than the number of closing brackets?
Also please explain the test case.
And can a or b be an empty string?

Is it an indication of the type of data type to be used to print the answer “Print the answer with modulo 10^9 + 7” ?

Hi @sagnik.pal2017, yes a and b can be empty. 10^9 + 7 indicates the data type to be used.

Can you please explain how the output is printed for the example test case given in the problem ?

Just output the no. of possible combinations of a and b. Consider following exapmle:
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:

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

Hence, the ans for this testcase is 5 and thus output to printed is just 5. If there is no possible combination then print -1.

If you are indicating towards how to use mod 10^9+7 then, whenever you are sure that a possible combination of and b generated is valid and you will be incrementing your count variable then just do this:

count = (count + 1)%1000000007 ;

Pls try the question now. Hope this helps :slight_smile: