Light OJ — Making Huge Palindromes

Revision en1, by LegendaryNewbie_, 2020-04-17 11:21:02

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];

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English LegendaryNewbie_ 2020-04-17 11:43:58 20
en2 English LegendaryNewbie_ 2020-04-17 11:22:17 10 Tiny change: 'is case.\nint pref' -> 'is case.\n\n\n\n\nint pref'
en1 English LegendaryNewbie_ 2020-04-17 11:21:02 938 Initial revision (published)