← 返回首页
Add Longest Common Substring algorithm by fauzan171 · Pull Request #802 · TheAlgorithms/Go · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Add Longest Common Substring algorithm#802

Open
fauzan171 wants to merge 1 commit into
TheAlgorithms:masterfrom
fauzan171:add-levenshtein-distance
Open

Add Longest Common Substring algorithm#802
fauzan171 wants to merge 1 commit into
TheAlgorithms:masterfrom
fauzan171:add-levenshtein-distance

Conversation

Copy link
Copy Markdown

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:

  • 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

Checklist

  • Code follows project style guide (STYLE.md)
  • Includes comprehensive tests
  • Proper documentation with time/space complexity
  • No external dependencies

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.
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity · 0 duplication
Metric Results
Complexity 12
Duplication 0

View in Codacy

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
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

Footer

© 2026 GitHub, Inc.