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.
Hey guys, I think the easiest (and the most logical) approach would be to use suffix trees.
This problem is naturally reduced to "longest common substring" problem if you reverse the second string.
There is time- and space-efficient O(n + m) solution for that, using Ukkunen's algorithm.
But unfortunately the algorithm is quite complex.
Based on the length of input (~10^5), no O(n^2) algorithm will work here.
Maybe O(n*log(n)) will still do...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Build a Palindrome
You are viewing a single comment's thread. Return to all comments →
Hey guys, I think the easiest (and the most logical) approach would be to use suffix trees. This problem is naturally reduced to "longest common substring" problem if you reverse the second string. There is time- and space-efficient O(n + m) solution for that, using Ukkunen's algorithm. But unfortunately the algorithm is quite complex.
Based on the length of input (~10^5), no O(n^2) algorithm will work here. Maybe O(n*log(n)) will still do...