You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
Added the Longest Common Substring algorithm using dynamic programming.
Difference from existing code:
The repo already has longestcommonsubsequence.go (Longest Common Subsequence), but Longest Common Substring is a different problem - the substring must be contiguous in both strings, whereas subsequence allows non-contiguous matches.
Implementation:
Time complexity: O(m * n)
Space complexity: O(m * n)
Uses a DP table where dp[i][j] represents the length of the longest common substring ending at str1[i-1] and str2[j-1]
Test Coverage:
12 test cases covering:
Basic matching
Full string match
No match
Empty strings
Single character cases
Substring at start/end
Repeated characters
Overlapping patterns
All tests pass: go test ./dynamic/ -run TestLongestCommonSubstring -v
Implemented the Longest Common Substring algorithm using dynamic programming.
Unlike Longest Common Subsequence (which already exists), the substring
must be contiguous in both strings.
Time complexity: O(m * n)
Space complexity: O(m * n)
Includes comprehensive test suite with 12 test cases covering edge cases.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added the Longest Common Substring algorithm using dynamic programming.
Difference from existing code:
The repo already has longestcommonsubsequence.go (Longest Common Subsequence), but Longest Common Substring is a different problem - the substring must be contiguous in both strings, whereas subsequence allows non-contiguous matches.
Implementation:
Test Coverage:
12 test cases covering:
All tests pass: go test ./dynamic/ -run TestLongestCommonSubstring -v
Checklist