n1e2m3's blog

By n1e2m3, history, 5 weeks ago, ,

given a string S. you have to find maximum product of length of two non overlapping palindromic sequence.
here, non overlapping means only indexes are non overlap.

for example,

1)
s = “abcab”
ans = 3*2 = 6
two palindromic sequence are “aca” and “bb”

2 )
s = nriatdoiarn
ans = 5*5 = 25
two palindromic sequences are “nitin” and ( “radar” or “raoar”)

3 )
s = “abcdef”
ans = 1*1 = 1

• +11

 » 5 weeks ago, # | ← Rev. 3 →   0 [Deleted]
•  » » 5 weeks ago, # ^ |   0 Could you elaborate more about how to find the length of the longest palindromic subsequence in O(n*logn)?
•  » » » 5 weeks ago, # ^ | ← Rev. 3 →   0 Sorry misread the statement ;_;
 » 5 weeks ago, # |   +1 Please, someone answer it. This appears to be a very good question to me.
 » 5 weeks ago, # |   +5 stackexchange code is wrong
 » 5 weeks ago, # | ← Rev. 3 →   0 Wrong idea
•  » » 5 weeks ago, # ^ |   0 yes it is wrong on accbcac
 » 5 weeks ago, # | ← Rev. 3 →   0 What about the stack exchange answer. It looks correct to me, and is $O(n^{2})$. Please point out if something is wrong.So another question is, for $A$ and $B$ to be non overlapping subsequences of given string $S$, what is the exact criteria?Since $A$ = $S[i_1]$,$S[i_2]$, ... , $S[i_{n1}]$, and $B$ = $S[j_1]$,$S[j_2]$, ... , $S[j_{n2}]$ so which of the following do we want: ( assuming $i_1$ < $j_1$ )$1)$ $i_{n1} \lt j_1$ ( basically for some string, "abcdefg" if I take $A$ = "ace" then can I only take letters after 'e' for $B$? )OR$2)$ $i_x != j_y$ for each $x$ in $range(1,n1)$ ,$y$ in $range(1,n2)$. ( no two characters of the same index )I believe the stack exchange answer is definitely valid, in case of definition $1)$ of non overlapping subsequences.UPD: I guess the example $2$ given in the post, makes it clear that the $2)$ definition is the one to be used.
•  » » 5 weeks ago, # ^ | ← Rev. 3 →   +1 accbcac its ans is 12 its showing 6, author's concept might be correct,but implementation is wrong. link
•  » » » 5 weeks ago, # ^ |   0 How it's answer is 12? It should be 6.
•  » » » » 5 weeks ago, # ^ |   0 aba * cccc
•  » » » 5 weeks ago, # ^ | ← Rev. 2 →   0 Interesting example. It looks like longest palindromic subsequence dp will fail to give us required answer. For $accbcac$, lps is length $5$ ( either $accca$ or $ccbcc$ or $acbca$ ), but we need $aba$ and $cccc$ for maximum product.
•  » » » » 5 weeks ago, # ^ |   0 i know one greedy approach,we know that for sure for palindrome pair both characters should be at maximum distance.but we should insert them in two sets in such way that they should for approximate equal length.
•  » » 5 weeks ago, # ^ |   0 We can also do like max(dp[1][j]*dp[j+1][n-1])
 » 5 weeks ago, # | ← Rev. 2 →   0 Wrong idea, misread the problem statement.
•  » » 5 weeks ago, # ^ |   +1 Yeah, you need to consider subsequences, not substrings. And even among subsequences, it is not necessary that subsequences will not interleave ( but definitely not intersect ).
•  » » » 5 weeks ago, # ^ |   0 yeah