Skip to content

Fix/palindrome separator collision - #2772

Merged
keon merged 2 commits into
keon:mainfrom
Miladkhoshdel:fix/palindrome-separator-collision
Sep 18, 2026
Merged

keon merged 2 commits into
keon:mainfrom
Miladkhoshdel:fix/palindrome-separator-collision

Conversation

@Miladkhoshdel

Copy link
Copy Markdown
Contributor

Summary

Fix longest_palindrome when the input contains #.

Problem

longest_palindrome("a#a") returned "aa", which is not a substring of the input. The algorithm used # as an internal separator and removed all # characters from the result.

Changes

  • Use a unique internal separator that cannot occur in the input.
  • Slice the result from the original string to preserve its characters.
  • Add regression tests for "a#a" and "##".

Testing

  • python3 -m unittest discover -s tests -p 'test_string.py' -v — 68 tests passed.

Related issue

Issue #2771

Fixes #2771

@keon
keon merged commit 25772ca into keon:main Sep 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

longest_palindrome drops # characters from the result

2 participants