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

How can I find a common pattern between 2 urls

I'd like to find the common pattern between 2 URLs in PHP. I've played around with https://gist.github.com/chrisbloom7/1021218 but that stops at the point of finding the longest match not accounting for wildcards that exist in URLs. e.g. here are 2…
illmatic
  • 43
  • 1
  • 8
0
votes
1 answer

How to find a longest consecutive repeated substring in a string?

In order to de-crypt a message, I need to first find the key. From the given information, I find the key is part of the string: str = "251220825122082" We can easily get that the key should be "2512208" since the key is supposed to be repeatedly…
Bella Wang
  • 21
  • 1
  • 9
0
votes
2 answers

Length of the Longest Common Substring without repeating characters

Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1. Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and…
Elroy Jetson
  • 938
  • 11
  • 27
0
votes
0 answers

PythonQuestion on Longest Common Substring(LCS) algorithm

I'm pretty new to Python, it's my first programming language, and I've wanted to work on some manual data structure manipulation and playing around. I've recently been learning the basic algorithm for solving the LCS problem, and I understand how…
LoganK
  • 1
  • 1
0
votes
2 answers

Longest repeated substring with at least k occurrences correctness

The algorithms for finding the longest repeated substring is formulated as follows 1)build the suffix tree 2)find the deepest internal node with at least k leaf children But I cannot understand why is this works,so basically what makes this…
0
votes
1 answer

Longest increasing subsequence in O(n) time?

I'm studying this algorithm for the first time. CLRS (15-4.6) asks to write an algorithm to run in O(n lg n) time. The algorithm I came up with seems to run in O(n). I think I must be misunderstanding something, because even wikipedia says it…
T.J. Gaffney
  • 115
  • 5
0
votes
1 answer

Longest Common Substring using Recursion and DP

I'm trying to find the Longest Common Substring of two strings using Recursion and DP. Please note that I'm not referring to Longest Contiguous subsequence. So, if the two strings were String s1 = "abcdf"; String s2 = "bzcdf" Longest Common…
0
votes
1 answer

Return the size of the larger sequence between two given strings

Well, my problem is: I have to return the size of the larger sequence between two given strings. My code at the moment: public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader( new…
developer033
  • 24,267
  • 8
  • 82
  • 108
0
votes
1 answer

MySQL longest common substring

Does anybody have a MySQL function for longest common substring (LCS)? I found a function here, but in SQL. As a self-taught programmer I don’t know much MySQL, but working on art-with-language project.
Rossa Urs
  • 17
  • 5
0
votes
1 answer

Suffix array/suffix tree with numbers

Can suffix trees or suffix arrays be used effectively with numbers? For example: Can it be used with the array [1,2,3,4,5,3,9,8,5,3,9,8,6,4,5,3,9,11,9,8,7,11] to extract all possible non-overlapping repeating sub-strings of all sizes from the…
0
votes
1 answer

Naive Approach to Longest Common Subsequence

We studied dynamic programming theory over Fall quarter, and I'm trying to brush up and continue further studies into it. I'm currently trying a naive approach into the LCS problem as mentioned in this TopCoder article: Dynamic Programming The…
Parity Bit
  • 113
  • 1
  • 12
0
votes
1 answer

How to find all common longest substrings of a list of strings

I have a list of strings for which I need to find ALL common unique substrings (actually paths) with minimal length in them. Example: /a/b/c /a/b /a /d/e/f /d/e /g/h For this input, I need the following result: /a /d/e /g/h As you see, I…
0
votes
1 answer

Output of longest palindrome in a string gets printed correctly in spite of not being part of stack

I wrote some code to find the longest palindrome in a string (the palindrome doesn't have to appear together, as in it can be non-contiguous) It works for almost all of the cases. For the case in code below too, it does print out the correct…
tubby
  • 2,074
  • 3
  • 33
  • 55
0
votes
0 answers

Given a string find the longest substring with words that have 2 or more letter in common optimally

The text of the problem says so: Find the longest substring in a given string formed with words that have 2 or more letters in common(the words must be neighbours in the substring(one after the other)) . Restraint: running time must be lower than…
Lucian Tarna
  • 1,806
  • 4
  • 25
  • 48
0
votes
2 answers

Longest Increasing Subsequence code in O(N)?

Someone asked me a question Find the longest alphabetically increasing or equal string composed of those letters. Note that you are allowed to drop unused characters. So ghaaawxyzijbbbklccc returns aaabbbccc. Is an O(n) solution possible? and…
Deepanshu
  • 488
  • 6
  • 18