Skip to content

Refactor LongestCommonSubsequence#1282

Merged
williamfiset merged 5 commits into
masterfrom
refactor-lcs
Mar 11, 2026
Merged

Refactor LongestCommonSubsequence#1282
williamfiset merged 5 commits into
masterfrom
refactor-lcs

Conversation

@williamfiset

Copy link
Copy Markdown
Owner

Summary

  • Refactored LongestCommonSubsequence with file header, Javadoc, section headers, and inline comments
  • Renamed original method to lcsIterative, added lcs() convenience overloads (String and char[])
  • Added recursive implementation (lcsRecursive) using top-down memoization with Integer[][]
  • Added space-optimized lcsLength that computes LCS length in O(min(n, m)) space
  • Added 18 JUnit 5 tests covering null/empty inputs, single chars, identical strings, prefix/suffix matches, cross-validation between all three implementations

Test plan

  • bazel test //src/test/java/com/williamfiset/algorithms/dp:LongestCommonSubsequenceTest passes
  • bazel run //src/main/java/com/williamfiset/algorithms/dp:LongestCommonSubsequence produces expected output

🤖 Generated with Claude Code

@williamfiset williamfiset changed the title Refactor LongestCommonSubsequence with recursive and space-optimized variants Refactor LongestCommonSubsequence Mar 11, 2026
williamfiset and others added 5 commits March 10, 2026 22:20
…implementations, add tests

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@williamfiset williamfiset merged commit 915ea5f into master Mar 11, 2026
2 checks passed
@williamfiset williamfiset deleted the refactor-lcs branch March 11, 2026 05:25
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.

1 participant