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
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,026
  • 1
  • 13
  • 25
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
  • 1
  • 6
  • 15
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
  • 94,813
  • 90
  • 365
  • 641
3
votes
3 answers

How to print all possible solutions for Longest Common subsequence

I want to print all the possible solutions to LCS problem. The two strings abcbdab and bdcaba should print following 3 strings: bdab,bcba,bcab. C is the global matrix table which takes values according to algorithm and m, n are the length of the…
user2848299
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
  • 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
  • 18,496
  • 5
  • 23
  • 33
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
  • 533
  • 1
  • 11
  • 26
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…
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
  • 33
  • 5
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
  • 11
2
votes
1 answer

LRS using C program

So I want to create a function using C to find the longest repeated non overlapping substring in a given string. For example: input banana. Output: an. I was thinking using comparison of the array of the string and checking for repeats. Is that a…
tyc72
  • 65
  • 6
2
votes
1 answer

Longest Common Substring without cutting a word

I am very new in programming and I am trying to solve one of longest common sequence/substring problems in Java. So the algorithm question I am working on is to find longest common substring without cutting words. For instance: given string1 = He…
2
votes
1 answer

Longest palindromic substring top down recursive approach

I am trying to solve Longest palindromic substring on Leetcode. I a aware of solutions for this problem like expand around center or dynamic programming bottom up approach. For purely educational purposes I wanted to solve this in top down recursive…
Michal
  • 1,192
  • 1
  • 13
  • 31
2
votes
1 answer

Time complexity of an algorithm: find length of a longest palindromic substring

I've written a small PHP function to find a length of a longest palindromic substring of a string. To avoid many loops I've used a recursion. The idea behind algorithm is, to loop through an array and for each center (including centers between…
2
votes
5 answers

Find the longest substring in alphabetical order. What is wrong with my code

So far i've got : s = 'azcbobobegghakl' i = 0 j = 1 temp = '' #temporary variable I use to change longest longest = '' for b in range(len(s)): if s[i] <= s[j]: #checks if it's in alphabetical order temp+=s[i] if…
Skygear
  • 90
  • 6
1
2
3
10 11