I’m unable to understand what has to be done Please explain in with some examples.
Brackets all over challenge
Hi abhinav,share the question link here.
Hey Abhinav,
you can solve this problem using dynamic programming:
First calculate dp[i, j] i.e. 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.