Please read the new rule regarding the restriction on the use of AI tools. ×

Longest common prefix question

Revision en1, by arif.ozturk, 2018-01-23 22:30:26

Hello, I recently got an interesting question from my old teacher. Given two strings A and B(of size <=2000000) find the sum of the longest common prefixes of A and all substrings of B. I reduced this to finding the longest common prefix of A and all suffixes of B and found a solution in O(NlogN) time using suffix arrays. Because it consumed a lot of memory, I switched to hashing and it worked to some extent but it seems O(NlogN) is too large as I get TLE. I was thinking whether I could change the KMP algorithm a bit to get exactly what I need but I can't seem to find a way. Do you guys have any ideas?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English arif.ozturk 2018-01-23 22:30:26 644 Initial revision (published)