VERDICT: Wrong Answer....the problem is about to find the length of the smallest palindrome that can be formed by adding some additional character at it end(possibly zero). i used prefix function of original given string comparing with its reverse to find out the largest suffix in the original string that is a prefix of its reverse that means palindromes.For several test case i found it working but verdict is "Wrong Answwer".Can anyone help me with test case or tell me reason why it may not work in this case.
int prefix_function(string original, string rev)
{
string text = rev + '#' + original;
int n = text.size();
int m = original.size();
vector<int>lps(n);
for (int i = m + 1, j = 0; i < n; )
{
if (text[i] == text[j])
{
lps[i] = j + 1;
j++;
i++;
}
else
{
if (j != 0) j = lps[j - 1];
else lps[i] = 0, i++;
}
}
return lps[n - 1];
}