Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

minimum characters to make string palindrome

string s;
    int len=0,i=1;
    cin>>s;
    int n=s.size();
    vector<int> LPS(n);
    LPS[0]=0;
    while(i<n)
    {
        if(s[i]==s[len]) LPS[i++]=++len;
        else
        {
            if(len==0) LPS[i++]=0;
            else len=LPS[len-1];
        }
    }
Source by practice.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #minimum #characters #string #palindrome
ADD COMMENT
Topic
Name
7+3 =