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
0
votes
1 answer

Where am I going wrong in the basic implementation of Longest Common Subsequence

I've tried to implement LCS in python using the following code, where am I going wrong ? def lcs(s1,s2): if len(s1) == 0 or len(s2) == 0: return "" n = len(s1) - 1 m = len(s2) - 1 if s1[n] == s2[m]: …
0
votes
1 answer

Recursion : Print all longest common subsequence

Iam trying to print all possible longest common subsequence using below code 1-Firstly i found LCS length dp matrix and trying using recursion to produce all possible outputs. ################################################Print ALL LCS…
0
votes
2 answers

Trying to get the longest decreasing substring from a given string, keeping the case sensitivity in mind

I have been trying to get below result out of this Program but for some reason it is not giving the required output. Required Results: Input1 : bbaasssrppoccbaaacbaba Output1 : ['bbaa','sssrppoccbaaa','cba','ba'] Input2: hjgAvjhjKLhbfvbZSF …
0
votes
2 answers

Compare each element of two series/df with a custom function in pandas without a for-loop

I built a custom function two compare two url's to get the longest common subsequence (lcs). def lcs_dynamic(url1, url2): maths: compare url1 with url2 return lcs I have a series s1 and a series s2 with a bunch of url's (13.000pcs). I want…
TGee
  • 41
  • 1
  • 6
0
votes
0 answers

Recursive solution to longest common substring not working

I am trying to get the longest common substring recursively but for some reason my code is not working. def lcs(s, t): if not s or not t: return '' if s[0] is t[0]: return s[0] + lcs(s[1:], t[1:]) a = lcs(s[1:], t) …
Guilherme
  • 1
  • 1
0
votes
0 answers

Longest Repeating Subsequence length in python using recursion producing wrong results

I am trying to generate the longest repeating subsequence but the output appears to be incorrect for a few cases. Below is the code block I am using def LRSLength(X, m, n): # return if the end of either string is reached if m == 0 or n ==…
Mehul Gupta
  • 1,829
  • 3
  • 17
  • 33
0
votes
1 answer

Longest Common Subsequence not printing length matrix

I'm trying to implement Longest Common Subsequence algorithm in c, the matrices c[][] stores the length of the longest common subsequence, row[][] stores the parent block row in the c[][] matrix and col[][] stores the parent block column. I…
0
votes
1 answer

Longest Palindrome Substring : Index Error ( list index out of range)

Index Error , List index out of range In "if" statement, the second line gives the above specific error You can see the value of index(ind) being used for the list(temp). It is clearly not out of range but it still gives the error. def…
0
votes
1 answer

whats the problem with the given solution to the LCS problem?

I have a recursive solution to the longest common subsequence problem of two strings given below: def LCS(i, j, lcs): # i , j are the position of character in X and Y respectively which are being compared # lcs is the string…
Mr Sukhe
  • 67
  • 9
0
votes
2 answers

Find longest sequence of common words from list of words in python

I searched a lot for a solution and I indeed have found similar questions. This answer gives back the longest sequence of CHARACTERS that might NOT belong in all of the strings in the input list. This answer gives back the longest common sequences…
Stelios M
  • 160
  • 1
  • 1
  • 11
0
votes
2 answers

Max length chain

You are given N pairs of numbers. In every pair, the first number is always smaller than the second number. A pair (c, d) can follow another pair (a, b) if b < c. Chain of pairs can be formed in this fashion. Your task is to complete the function…
0
votes
2 answers

Find rows with the longest matching string

I have a dataframe composed of groups with corresponding animals as a string: data = data.frame(group = c(1,2,3,4), animal = c("cat, dog, horse, mouse", "cat, dog, horse", "cat, dog,", "cat, dog, frog, cow")) I would like to return groups where the…
LHordley
  • 95
  • 5
0
votes
1 answer

Getting Integer division and modulo by zero error

I'm getting Integer Division or Modulo by zero error. def getProduct(n): product = 1 while (n != 0): product = product * (n % 10) n = n // 10 return product def printSubstrings(n): s=int(math.log10(n)) …
0
votes
2 answers

How to write a function to find the longest common subsequence using dynamic programming?

To be clear I am looking for the subsequence itself and not the length. I have written this function which works the majority of the time but in some cases it doesn't work. I have to write this recursively without any loops or imports. I used a…
Gokira
  • 11
  • 2
0
votes
0 answers

Longest Substring Without Repeating Characters (for loop way)

LeetCode Question #3 https://leetcode.com/problems/longest-substring-without-repeating-characters/ Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. var lengthOfLongestSubstring = function(s) { var arr =…
auntR
  • 150
  • 1
  • 2
  • 15