Consider B to be a sequence of grouping symbols (, ), [, ], {, and }. B is called a Balanced sequence if it is of length 0 or B is of one of the following forms: { X } Y or [ X ] Y or { X } Y where X and Y are Balanced themselves. Example for Balanced : ( ) - { [ ] ( ) } [ ] - ...
Now the question is to find an efficient algorithm to find maximum length balanced subsequence (not necessarily contiguous) of a given input which is an string of these grouping symbols.
For example if input is ( ) { ( [ ) ] { ( ] ) } } [ ] , one of the max-length subsequences is ( ) { [ ] { ( ) } } [ ]
I am almost sure the solution is DP but anyway I solve it I find examples in which my algorithm doesn't work. there is only one approach I am sure about, which is a combination of DP and Divide and Conquer. But it is not efficient because anyway D&C part is going to solve some overlapping problems over and over again.