#2771·algorithms

longest_palindrome drops # characters from the result

Author: MiladkhoshdelCreated Sep 17, 2026Updated Sep 17, 2026

longest_palindrome drops # characters from the result

Bug

longest_palindrome uses # as an internal separator and removes every # before returning. When the input contains #, the result can be wrong.

Reproduction

Call longest_palindrome("a#a").

  • Expected: "a#a"
  • Actual: "aa" — not a substring of the input

Also, longest_palindrome("##") returns "" instead of "##".

Suggested fix

Use a unique internal separator and slice the result from the original input string.