Rolling-hash

6 articles

dsa8 min read

Shortest Palindrome — KMP Failure Function on a Concatenated String

Shortest Palindrome (LC 214) is a hard FAANG problem that hides a classic KMP application. Concatenate s with reversed(s) and the failure function reveals the longest palindromic prefix in linear time. Master this trick and you unlock half a dozen related KMP applications.

Read →