Skip to content

Fix Manacher boundary palindromes and literal separators - #15632

Closed
Shubham-Padkonde wants to merge 1 commit into
TheAlgorithms:masterfrom
Shubham-Padkonde:fix/manacher-palindrome-boundaries
Closed

Shubham-Padkonde wants to merge 1 commit into
TheAlgorithms:masterfrom
Shubham-Padkonde:fix/manacher-palindrome-boundaries

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests?
  • Documentation change?

Use separators at both ends of the transformed string so Manacher's algorithm handles palindromes touching an input boundary. Map the resulting bounds back to the original input instead of stripping every |, which also removed literal input characters. The same construction handles empty input.

Examples: abb previously returned b, now bb; a|a previously returned aa, now a|a; empty input previously raised IndexError, now returns an empty string. The boundary issue was previously identified by @okcd00 in the closed, unmerged #6231; this change also handles literal separators and empty input.

Validation on free-threaded Python 3.15: all 9,841 strings over ab| up to length 8 checked against an exhaustive substring oracle. Six existing Manacher/palindrome doctest items pass, as do all applicable pre-commit hooks. The boundary regression fails before the fix. Existing doctests remain unchanged, per the contribution guidance.

AI-assisted contribution.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass.

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Oct 23, 2026
@algorithms-keeper

Copy link
Copy Markdown

Multiple Pull Request Detected

@Shubham-Padkonde, we are extremely excited that you want to submit multiple algorithms in this repository but we have a limit on how many pull request a user can keep open at a time. This is to make sure all maintainers and users focus on a limited number of pull requests at a time to maintain the quality of the code.

This pull request is being closed as the user already has an open pull request. Please focus on your previous pull request before opening another one. Thank you for your cooperation.

User opened pull requests (including this one): #15632, #15631, #15630, #15629

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

Labels

awaiting reviews This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant