Questions tagged [longest-substring]

Longest Substring is a classic computer science problem: given two strings, find the common strings, then return the string(s) in common with the greatest length.

The longest common substring problem is a derivative of the edit distance problem, which focuses on the most common typing errors:

  • namely character omissions
  • insertions
  • substitutions
  • reversals

The idea is to compute the minimum number of operations that it would take to transform one string into another. The longest common substring problem follows with the following constraints:

  • substitutions are forbidden
  • only exact character match, insert, and delete are allowable edit operations

References

160 questions
61
votes
9 answers

Longest common substring from more than two strings - Python

I'm looking for a Python library for finding the longest common sub-string from a set of strings. There are two ways to solve this problem : using suffix trees using dynamic programming. Method implemented is not important. It is important it can…
Nicolas NOEL
  • 821
  • 1
  • 6
  • 7
13
votes
1 answer

Longest repeated (k times) substring

I know this is a somewhat beaten topic, but I have reached the limit of help I can get from what's already been answered. This is for the Rosalind project problem LREP. I'm trying to find the longest k-peated substring in a string and I've been…
Gambrinus
  • 133
  • 1
  • 7
11
votes
3 answers

Longest Subsequence with all occurrences of a character at 1 place

In a sequence S of n characters; each character may occur many times in the sequence. You want to find the longest subsequence of S where all occurrences of the same character are together in one place; For ex. if S =…
pxm
  • 1,442
  • 1
  • 15
  • 31
9
votes
7 answers

How to compare 2 lists and return a list of the greatest subset?

I want to compare two ArrayLists and return the greatest subset of similarities in Java. So I want to compare parts of the list not just single values. Example: list 1 list 2 F A A B B C C F D …
Cees Mandjes
  • 195
  • 12
8
votes
4 answers

R - Longest common substring

Does anyone know of an R package that solves the longest common substring problem? I am looking for something fast that could work on vectors.
gappy
  • 9,677
  • 13
  • 51
  • 72
7
votes
2 answers

How to determine the number of possible combinations of letters that contain a degenerate substring

I've been racking my brain for a couple of days to work out a series or closed-form equation to the following problem: Specifically: given all strings of length N that draws from an alphabet of L letters (starting with 'A', for example {A, B}, {A,…
7
votes
1 answer

Python Difflib's SequenceMatcher does not find Longest Common Substrings

I want to use difflib.SequenceMatcher to extract longest common substrings from two strings. I'm not sure whether I found a bug or misunderstood the documentation of find_longest_match. This is the point that I find confusing: In other words, of…
Lukas Barth
  • 2,078
  • 11
  • 36
6
votes
1 answer

Python: Length of longest common subsequence of lists

Is there a built-in function in python which returns a length of longest common subsequence of two lists? a=[1,2,6,5,4,8] b=[2,1,6,5,4,4] print a.llcs(b) >>> 3 I tried to find longest common subsequence and then get length of it but I think there…
Milano
  • 13,773
  • 29
  • 96
  • 240
5
votes
3 answers

Longest recurring cycle of digits

I'm trying to find the number less than 1000 that produces the longest string of repeated numbers when it divides 1. I have a list of decimal numbers and have to find the ones which have the longest repeated sequence. Here's what I have so…
Richard Hamilton
  • 22,314
  • 9
  • 45
  • 77
5
votes
5 answers

Java implementation for longest common substring of n strings

I need to find the longest common substring of n strings and use the result in my project. Is there any existing implementation/library in java which already does this?
user1628340
  • 711
  • 4
  • 11
  • 25
4
votes
1 answer

Longest common substring from more than two strings - C++

I need to compute the longest common substrings from a set of filenames in C++. Precisely, I have an std::list of std::strings (or the QT equivalent, also fine) char const *x[] = {"FirstFileWord.xls", "SecondFileBlue.xls", "ThirdFileWhite.xls",…
user2707001
  • 1,143
  • 10
  • 13
4
votes
1 answer

Longest Common Substring with wrong character tolerance

I have a script I found on here that works well when looking for the Lowest Common Substring. However, I need it to tolerate some incorrect/missing characters. I would like be able to either input a percentage of similarity required, or perhaps…
3
votes
7 answers

Recursive Longestword programming

I have done it finally like what I want. Thank you all for helping and I want to emphasize that it was NOT homework. public static void main(String[] args) { String input = "Java is a programming language"; StringTokenizer st = new…
John Myung
  • 41
  • 4
3
votes
2 answers

greatest common divisor for strings in python

I would like to have a python function that given the list mystrings = ['abcde', 'abcdf', 'abcef', 'abcnn'] returns the string 'abc', i.e., the longest piece contained by all the elements in the list. I have a solution which just loops through the…
v923z
  • 1,157
  • 3
  • 13
  • 24
3
votes
1 answer

longest palindromic substring using lcs?

I was solving this longest palindromic substring problem on leetcode and I followed the dynamic programming approach by creating one n*n boolean table(which I guess is also the standard solution to this) and successfully solved it but I was just…
1
2 3
10 11