Brackets all over

please clear its logic

@rishabhmahajan546
…please clear it sir

@shampblocks hi bro,This problem can be solved with dynamic programming:

Calculate dp[i, j] : How many sequences of brackets of length i has balance j and intermediate balance never goes below zero (They form a prefix of a valid sequence of brackets).

For the given sequence of length n calculate the resulting balance a and the minimum balance b.

Try the length of the sequence added at the beginning c and its balance d. If - b ≤ d then add dp[c, d] × dp[m - n - c, d + a] to the answer.

Time complexity: O((n - m)^2)

sir all TA’s are sending this statement can you clear it in simple mannner??

@shampblocks bhai ye 3d dp wala solution hai ,ek bar ise dry run krke dekho and logic smjh ajayega easily jaisa mene upr btaya hai:


Agar fir bhi na aye then i will help you.

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.