Skip to content

perf(strings): optimize LongestCommonSubstring DP memory to O(N) and … - #7613

Merged
DenizAltunkapan merged 4 commits into
TheAlgorithms:masterfrom
irenemrtinez:fix/add-javadoc-to-maths
Sep 22, 2026
Merged

DenizAltunkapan merged 4 commits into
TheAlgorithms:masterfrom
irenemrtinez:fix/add-javadoc-to-maths

Conversation

@irenemrtinez

Copy link
Copy Markdown
Contributor

Summary

  • Memory Optimization: Refactored LongestCommonSubstring to use a 1D DP array (O(min(N, M)) dynamic memory) instead of a 2D matrix (O(N * M)).
  • Performance Improvements: Prevents memory overload and timeouts when running string comparisons on large inputs ($4000+$ characters). With the old code, the new test I created failed
  • Test Coverage: Added comprehensive unit tests in LongestCommonSubstringTest.java covering unicode characters, whitespace, repeated patterns, null/empty inputs, and boundary conditions.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.18%. Comparing base (87edc62) to head (63a4aba).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7613      +/-   ##
============================================
- Coverage     81.19%   81.18%   -0.02%     
+ Complexity     7900     7897       -3     
============================================
  Files           830      830              
  Lines         25012    25012              
  Branches       4882     4882              
============================================
- Hits          20308    20305       -3     
  Misses         3920     3920              
- Partials        784      787       +3     

☔ View full report in Codecov by Harness.
📢 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.

@irenemrtinez
irenemrtinez marked this pull request as ready for review September 22, 2026 13:58
@DenizAltunkapan
DenizAltunkapan merged commit b2b9d3a into TheAlgorithms:master Sep 22, 2026
7 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.

3 participants