Resource · Guide or article
Longest Common Substring Problem
Defines the longest common substring problem across two or more strings and illustrates it with a three-string example.
Reviewed
Open the original: Longest Common Substring Problem (opens the original site in a new tab)Practice this topicOpens the practice interviewer in Technical / coding mode; choose a question there.
Add to a roadmap
Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.
Source content: English
The longest common substring problem is to find the longest string (or strings) that is a substring (or are substrings) of two or more strings. The longest common substring of the strings ABABC, BABCA and ABCBA is string ABC of length 3. Other common substrings are A, AB, B, BA, BC and C.
PrepKit overview
PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.
- Suited to
- The source does not state a level
- Format
- Reference
What it covers
- Finds ABC as the longest shared substring of ABABC, BABCA and ABCBA, and lists the shorter shared substrings
- Includes a small text diagram that lines up the match
How to use it
PrepKit study advice, not a claim made by the source.
Write the two-string DP solution yourself, then confirm it returns ABC for the first two example strings.
Scope and limitations
No solution method, complexity or code discussion appears on the page. It points to Wikipedia and a YouTube video for the approach.
Access and format
Very short README on GitHub, trekhleb/javascript-algorithms (MIT). English, free to read.
Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88
Evidence behind this overview
- src/algorithms/string/longest-common-substring/README.md
Pages that include this
Get the PrepKit newsletter
Optional. You don't need it to use PrepKit.