HSBC contest question, similar to Longest Palindromic Subsequence. Image attached


Sample Input - aabbaab
Sample Output - 6 (subsequence aabaab)
Sample Input - aklbjanb
Sample Output - 4(subsequence abab)
1<=Length of string<=100

Yes, it seems similar with a difference that answer cannot be odd.

So what?

Could you solve it?

Solve what?

The question I posted…

I have an O(n3) approach for this.
Implementation: fnKhd6 - Online C++0x Compiler & Debugging Tool - Ideone.com.
So, I basically divide the string into two parts and then recur for the starting and ending points of the two segments (denoted by l1,r1,l2,r2 in the code).
PS: I tried reducing a “state” but was unable to do so.