Skip to content

feat: add longest repeating subsequence algorithm#14856

Open
JPisOP007 wants to merge 1 commit into
TheAlgorithms:masterfrom
JPisOP007:feat/add-longest-repeating-subsequence
Open

feat: add longest repeating subsequence algorithm#14856
JPisOP007 wants to merge 1 commit into
TheAlgorithms:masterfrom
JPisOP007:feat/add-longest-repeating-subsequence

Conversation

@JPisOP007

Copy link
Copy Markdown

Describe your change:

Add a dynamic programming implementation of the Longest Repeating Subsequence (LRS) algorithm to the dynamic_programming directory.

The Longest Repeating Subsequence finds the longest subsequence that occurs at least twice in a string, using a variation of LCS where the string is compared with itself but characters at the same index cannot be reused.

Features:

  • O(n²) time and space complexity using dynamic programming
  • Comprehensive doctests covering valid inputs, edge cases, and error handling
  • Python type hints for parameters and return values
  • Proper error handling with TypeError for invalid input types

Reference: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • An existing algorithm or test needs improvement?
  • Documentation change?

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 new Python files are placed inside an existing directory.
  • 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 the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

Add a dynamic programming implementation of the Longest Repeating Subsequence (LRS) algorithm. This finds the longest subsequence that occurs at least twice in a string, using a variation of LCS where the string is compared with itself but characters at the same index cannot be reused. Includes comprehensive doctests and type hints.
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Jun 24, 2026
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.

2 participants