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.
Play with words
Play with words
Sort by
recency
|
37 Discussions
|
Please Login in order to post a comment
Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Play with words Problem Solution
Struggled a bit on this but wound up with modified code for longest palindromic subsequence:
Here is Play with words problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-play-with-words-problem-solution.html
Slight rough code but it works for longest pallindromic subsequence
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.