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
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
  • 7
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
3 answers

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,324
  • 2
  • 16
  • 38
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
2
votes
3 answers

Finding longest common matching substring from given List in a string

I have a list of strings, which I want to find the start and end indices of their occurrence in a given string. I want to find the longest common substring that is present in the original string and only print it. Here is my code: public static void…
Kunal Mukherjee
  • 5,775
  • 3
  • 25
  • 53
2
votes
2 answers

Longest sequence of numbers

I was recently asked this question in an interview for which i could give an O(nlogn) solution, but couldn't find a logic for O(n) . Can someone help me with O(n) solution? In an array find the length of longest sequence of numbers Example : Input…
Amogh Huilgol
  • 1,252
  • 3
  • 18
  • 25
2
votes
3 answers

Longest Common substring breaking issue

Hi I have a function that finds the longest common substring between two strings. It works great except it seems to break when it reaches any single quote mark: ' This causes it to not truly find the longest substring sometimes. Could anyone help me…
Zach Johnson
  • 2,047
  • 6
  • 24
  • 40
2
votes
1 answer

Levenshtein divides in too many substrings

I've implemented the Levenshtein distance to do signal alignment. There are cases where Levenshtein doesn't find the solution I want, although it's optimal. For example, I have the strings: aaabaa abaaabaaa The algorithm should recognize that it…
2
votes
1 answer

I have a vector of characters say A,G,C,T. I want the longest sequence of A from the vector using R

set.seed (12345) data <- paste(sample(c("A","C","G","T"),100000,replace=TRUE,prob=rep(0.25,4))) data <- ifelse(data=="A",1,0) Suppose I convert the data into 1 (desired character) and 0 (else). Then take sum at each positions. If sum upto a…
madmathguy
  • 23
  • 1
  • 7
2
votes
2 answers

Why we don't use prefix tree (trie) to find longest common substring?

Recently I am learning how to use tree to solve the longest common substring problem. After learning from Wiki and other online resources, I found that we should use suffix tree to find longest common substring. As the wiki said: The longest…
JoJo
  • 1,377
  • 3
  • 14
  • 28
2
votes
0 answers

Find similar blocks of texts

I'm trying to extract (long) repeating blocks of the same code, and have the regular flow of execution jump to/from those block when needed. This is done over an educational assembly language called Hack. How can I extract those blocks. I…
Trevor
  • 1,858
  • 4
  • 21
  • 28
2
votes
3 answers

Approach to Longest Common Substring

In the Programming Challenge in the Common Child , i have taken a different approach than the general Longest Common Substring problem. The Code is #include #include #include #include #include #include…
Shaurya Chaudhuri
  • 3,772
  • 6
  • 28
  • 58
2
votes
1 answer

Go : longest common subsequence to print result array

I have implemented Longest Common Subsequence algorithm and getting the right answer for longest but cannot figure out the way to print out what makes up the longest common subsequence. That is, I succeeded to get the length of longest commond…
user2671513
2
votes
1 answer

why is this parallel function for computing the longest common subsequence slower than the serial?

The parallel computation of the LCS follows the wavefront pattern. Here is the parallel function that is slower than a serial implementation. (I think that the number of diagonals(parallel) vs number of rows(serial) has something to do with it) void…
frkvr
  • 38
  • 7
1 2
3
12 13