We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here it is in python3.
This is similar to the LPS (longest Palindrom Subsequence) problem. You first build the matrix memo[i][j], which is the max subsequence palindrom in the substring s[i:j+1] and then use that matrix to check all possible partitioning of the string into two parts.
Notice that iterating over all posible divisions of the string and calling lps on both sides will be much too slow.
Play with words
You are viewing a single comment's thread. Return to all comments →
Here it is in python3. This is similar to the LPS (longest Palindrom Subsequence) problem. You first build the matrix
memo[i][j]
, which is the max subsequence palindrom in the substrings[i:j+1]
and then use that matrix to check all possible partitioning of the string into two parts.Notice that iterating over all posible divisions of the string and calling lps on both sides will be much too slow.