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

181 questions
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,237
  • 5
  • 15
  • 25
3
votes
2 answers

Longest common substring via suffix array: do we really need unique sentinels?

I am reading about LCP arrays and their use, in conjunction with suffix arrays, in solving the "Longest common substring" problem. This video states that the sentinels used to separate individual strings must be unique, and not be contained in any…
Wad
  • 1,454
  • 1
  • 16
  • 33
3
votes
1 answer

Longest common sub string in a set of strings JavaScript

I was trying to find longest common substring in a set of strings in JavaScript. I got the idea from Find the longest common starting substring in a set of strings but I am not only looking for staring sub string So, I went ahead with following: I…
StrugglingCoder
  • 4,781
  • 16
  • 69
  • 103
3
votes
1 answer

How do you combine similar strings for counting purposes in SQL Server

I built a query that finds the longest common substrings of a column and orders them by frequency. The problem I'm having is removing/grouping similar results. Here's the TOP 5 output from the code below - note how "I love mittens the cat" is the…
Fubudis
  • 241
  • 3
  • 6
  • 17
3
votes
9 answers

Longest Common Substring without cutting a word- python

Given the following, i can find the longest common substring: s1 = "this is a foo bar sentence ." s2 = "what the foo bar blah blah black sheep is doing ?" def longest_common_substring(s1, s2): m = [[0] * (1 + len(s2)) for i in xrange(1 +…
alvas
  • 115,346
  • 109
  • 446
  • 738
3
votes
1 answer

Longest common substring bug

I have made this so far function lcs(xstr, ystr) if xstr:len() == 0 or ystr:len() == 0 then …
Jakub Tětek
  • 161
  • 1
  • 1
  • 7
3
votes
2 answers

Is this method of Longest common substring correct?

I have found an algorithm for Longest Common Substring. It is usually done using dynamic programming, using a 2-D array of size mxn where m and n are lengths of the two strings under consideration. I will construct the following matrix for the two…
nitish712
  • 19,504
  • 5
  • 26
  • 34
3
votes
2 answers

Longest repeated substring

learning python as I go for school work. Essentially, I need to find the longest repeated substring in a list of string as shown here. I have been reading through this article and have an understanding of what I should do. so far my implementation…
KidBatman
  • 585
  • 1
  • 13
  • 27
3
votes
2 answers

Finding the First Common Substring of a set of strings

I am looking for an implementation of a First Common Substring Mike is not your average guy. I think you are great. Jim is not your friend. I think you are great. Being different is not your fault. I think you are great. Using a Longest Common…
theChrisMarsh
  • 308
  • 1
  • 7
2
votes
1 answer

Longest Substring Without Repeating Characters - Need to Understand the Algorithm for given C# Solution

Problem: Longest Substring Without Repeating Characters. I have this solution. But I do not have much of theoretical knowledge about DSA. Trying to understand which algorithm it comes under and will it be efficient than 'Sliding Window'…
2
votes
2 answers

The longest repeating substrings JavaScript

I have a programm that can find the longest repeating substring of entered string, but the thing is, when there are 2 repeating substrings of the biggest length in answer I get only one of them. For instance, for the string 123b456k123m456j the…
Alice
  • 45
  • 6
2
votes
1 answer

Longest repeated substring in massive string

Given a long string, find the longest repeated sub-string. The brute-force approach of course is to find all substrings and check the substrings of the remaining string, but the string(s) in question have millions of characters (like a DNA sequence,…
Dragon-Ash
  • 71
  • 1
  • 1
  • 9
2
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…
2
votes
2 answers

How to find longest prefix from array list using given string value in Java?

String[] num = { "1201", "12018", "1201800","12018000" }; String prefix="120180000175135"; I have two variables one is String array and other one is String. Now I want to get longest value from String array using prefix. Please suggest me how can…
Kamal Kumar
  • 194
  • 12
2
votes
1 answer

How to find all longest common substrings that exist in multiple documents?

I have many text documents that I want to compare to one another and remove all text that is exactly the same between them. This is to remove find boiler plate text that is consistent so it can be removed for NLP. The best way I figured to do this…
AlanPear
  • 737
  • 1
  • 11
  • 32
1
2
3
12 13