Minimum Characters to Add at Front for Palindrome

Asked atFactSet Research Systems Inc.
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Find the longest palindromic prefix
  2. 02Build s + separator + reverse(s)
  3. 03Compute its LPS array
  4. 04Use the last LPS value as prefix length
  5. 05Add the reversed remaining suffix

Reference answer

Then expect these follow-ups

  • How would Manacher compare here?

    Tests: follow-up reasoning

  • How do you construct the final palindrome?

    Tests: follow-up reasoning

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question