instagram

Shortest Palindrome

Given a string s, form a shortest palindrome by appending characters at the start of the string

abab = babab

Here we are going to use KMP method to get shortest palindrome.

Input : abab
Output : Shortest Palindrome : babab

Input : abc
Output : Shortest Palindrome : cbabc

Algorithm


Share