Skip to content

longest_palindrome drops # characters from the result #2771

Closed

Description

@Miladkhoshdel

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.

Activity

  1. Miladkhoshdel commented on Sep 17, 2026

    @Miladkhoshdel
    ContributorAuthor

    A fix for this issue is available in PR #2772. It preserves # characters in the result and adds regression tests for "a#a" and "##".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions