Bracket subsequences problem

The problem is just the same as the one CHEFBR of December Challenge with the difference that we are given the input string having characters (,). We now have to count the valid number of parenthesis subsequences. I changed just the input format of CHEFBR solution and calculated here. But during the contest I didn’t come up with this and was trying understand this solution. Can someone please explain what the sec solution of quora says and how it is computing? As I got, I think the solution asks to find all possible valid parenthesis sequences for a given possible n and store in a set. Now, we are supposed to find how many times any string of this set occurs in the original input sequence. Is it? I don’t think its efficient then.

1 Like