Can you please elaborate on the problem, I mean what is required to do in the problem—
BrAackets all over problem
Hey @AbhishekAhlawat1102,
You are given an input string s, which will only contain open or close brackets.
For example: s=((( contains only opening and s=)) contains only closing.
You have to form a+s+b of size n, where a and b are any strings chosen by you and s is the given input string.
Now, the string a and b must be chosen such that string a+s+b, follows 2 properties:
i) At any index, number of opening brackets should be greater than closing brackets.
ii) No. of opening and closing brackets should be equal.
Now consider the given sample input:
4 2
((
here n =4 , string length = 2 and string s = “((”.
There is only one possible way to form a+s+b, with above two properties and with size = n.
i.e. take a = “” , b = “))”
a+s+b equals = “”+ “((” +"))"
Final output string = “(())”
The new string “(())” have above two properties.
Hence output will be 1, as there is only one way possible.
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.
hey @sanchit.bansal06
basically you are saying that
following values off is not given in the input.
))((( , (()(( , etc.
am i right ?
@rajujnvgupta,
If you are saying that s = ))(((
Then depending upon N we can find a solution for this too. If N = 10 then a can be (( and b can be ))).
Thus the string will be (())((())). Which is valid.
exactly ! but you are explicitly saying that s = “))(((” is not given in input.
what should be correct the input.
@rajujnvgupta,
I meant the string contains only opening bracket and closing bracket. No other character/symbol is being used.