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
1
vote
1 answer

Tracing a recursive function for longest common substring

I am getting confused tracing the following recursive approach to find the longest common substring. The last two lines are where my confusion is. Specifically how is the count variable getting the answer when characters of both string matches? In…
1
vote
4 answers

Concatenate array and return substring with longest repeating character

Let me preface with I AM A NEWBIE so take it easy on me please lol. I need help writing a function that takes an array of words and returns an object with the letter and the length of the longest substring of that letter. Each word in the array…
1
vote
2 answers

Finding contiguity by comparing kmers in R

Hello I have a dataframe which looks like this: LR ID Kmer ProcID 1 GTACGTAT 10 1 TACGTATC 10 1 ACGTATCG 2 1 GTATCGTT 3 2 GTTACGTA …
1
vote
2 answers

Count+Identify common words in two string vectors [R]

How can I write an R function that can take two string vectors and returns the number of common words AND which common words comparing element 1 from stringvec1 to element 1 of stringvec2, element 2 of strinvec1 to element 2 of stringvec2,…
Neal Barsch
  • 2,810
  • 2
  • 13
  • 39
1
vote
1 answer

Longest common prefix - comparing time complexity of two algorithms

If you comparing these two solutions the time complexity of the first solution is O(array-len*sortest-string-len) that you may shorten it to O(n*m) or even O(n^2). And the second one seems O(n * log n) as it has a sort method and then comparing the…
Hamid Mayeli
  • 805
  • 1
  • 14
  • 24
1
vote
1 answer

Performance of Longest Substring Without Repeating Characters in Haskell

Upon reading this Python question and proposing a solution, I tried to solve the same challenge in Haskell. I've come up with the code below, which seems to work. However, since I'm pretty new to this language, I'd like some help in understand…
Enlico
  • 23,259
  • 6
  • 48
  • 102
1
vote
1 answer

Longest Common Sequence optimization problem

I am trying to solve a problem which finds Longest Common Sequence between two strings. I used dynamic programming (DP) and I tried to optimize it. But I still get a timeout on HackerRank and I do not know why. I use the iterative version of…
1
vote
2 answers

Longest Palindromic Substring Problem - O(N^2 logN) Solution - Binary search

Longest Palindromic Substring Problem: Given a string s, return the longest palindromic substring in s. E.g. Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Questions The below code is the solution of Errichto (a RedCoder of…
Tarun
  • 25
  • 4
1
vote
1 answer

Longest Common Substring (using Intuition for Longest Common Subsequence)

I've been trying to learn Dynamic Programming. And I have come across two seemingly similar problems "Longest Common Subsequence" and "Longest Common Substring" So we assume we have 2 strings str1 and str2. For Longest Common Subsequence, we create…
Bernerd
  • 68
  • 5
1
vote
1 answer

Longest Substring without repeating characters - Code works during run , but fails on submit for the same testcase

class Solution: def lengthOfLongestSubstring(self, s: str,unique=[]) -> int: i=0 m=0 j=0 l=0 while(i
1
vote
1 answer

Trying to make an algorithm that checks a string, then outputs the longest substring

the only catch is that is has to be in alphabetical order: Where the unicode value is bigger than the previous character. If i have a string with the letters "owdnloquxat" then it would only print "loqux" since this is the longest substring in…
1
vote
0 answers

Finding longest match between list elements and dataframe column

Let's say I have a dataframe (df) with two columns and a list of strings (my_string). The objective is to find the longest match between each string in my_string to col_2 and insert the corresponding value of col_1 as an output. So, for instance,…
1
vote
2 answers

Find most common substring from an Array of Strings

I want to search a word from an array of strings. array = ["ram","gopal","varma","govind","ravan","alan"] if my search text is goal i want to list as follows: result = ["gopal","govind","alan"] ie in gopal & goal only p is missing so it should be…
Nikhil Raj
  • 49
  • 8
1
vote
4 answers

Longest Substring with no Y Divide and Conquer

Before I carry on to the problem, I should note that I know there are much easier ways to solve this problem without using divide and conquer; however, the point of solving this problem under this restriction is that I actually want to learn how to…
DrJessop
  • 462
  • 6
  • 26
1
vote
0 answers

Optimal algorithm to find-and-remove repeating patterns in collections

I recently came up to a real-world application of the algorithm I'll describe and found it interesting, so I thought I'd share and hope to get a better solution. It's somewhat similar to the popular "Longest repeated substring problem", and since…
milin
  • 414
  • 4
  • 14