Skip to content

Comments

Add Longest Repeated Substring algorithm#7286

Merged
DenizAltunkapan merged 2 commits intoTheAlgorithms:masterfrom
caglareker:feat/longest-repeated-substring
Feb 22, 2026
Merged

Add Longest Repeated Substring algorithm#7286
DenizAltunkapan merged 2 commits intoTheAlgorithms:masterfrom
caglareker:feat/longest-repeated-substring

Conversation

@caglareker
Copy link
Contributor

Summary

  • Add LongestRepeatedSubstring to the strings package, finding the longest substring that occurs at least twice in a given string
  • Reuses the existing SuffixArray.buildSuffixArray() and adds Kasai's algorithm for LCP (Longest Common Prefix) array construction
  • Overall complexity: O(n log² n) suffix array build + O(n) LCP scan

Why

This is a classic string algorithm commonly used in competitive programming, bioinformatics (DNA repeat detection), and data compression. It was a notable gap in the strings package, especially given that SuffixArray was already available as a building block.

Test plan

  • Added parameterized tests covering: typical cases ("banana""ana", "mississippi""issi"), edge cases (null, empty string, single character, no repeats), and direct LCP array verification

Implement LongestRepeatedSubstring in the strings package using the
existing SuffixArray and Kasai's algorithm for LCP array construction.
Includes parameterized unit tests covering typical and edge cases.
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2026

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.37%. Comparing base (109df1f) to head (b442997).

Files with missing lines Patch % Lines
...healgorithms/strings/LongestRepeatedSubstring.java 96.42% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7286      +/-   ##
============================================
+ Coverage     79.34%   79.37%   +0.02%     
- Complexity     7006     7021      +15     
============================================
  Files           784      785       +1     
  Lines         22991    23019      +28     
  Branches       4516     4523       +7     
============================================
+ Hits          18242    18271      +29     
  Misses         4020     4020              
+ Partials        729      728       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DenizAltunkapan
Copy link
Member

@caglareker Thank you for your contribution

@DenizAltunkapan DenizAltunkapan merged commit 12935c2 into TheAlgorithms:master Feb 22, 2026
7 checks passed
@caglareker
Copy link
Contributor Author

@caglareker Thank you for your contribution

Thank you for the review and merge. Happy to contribute. 🙏

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.

3 participants