Bracket All Over

Can you elaborate on this problem in a better way?

Hey @logic_0_found
This question is a clear dynamic programming question and can be solved by dp only because it is a clear combinatorial optimization problem.
what you have to do is think of a recursive approach first.

I am explaining the question to you.

Actually the question says that you have to generate the string of size n given m is the length of given string
Where m<=n

Now you have to generate a bracket string which is balanced
By adding a prefix and suffix string to given string s
Now the prefix string should have opening brackets greater than closing brackets, because the string should be overall be balanced.

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:

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

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