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

Longest common SUBSTRING optimization

Can anybody help me with optimization of my LONGEST COMMON SUBSTRING problem? I must read really big files (up to 2 Gb), but i cant figure out which structure to use... In c++ there is no hash maps.. There is concurrent hash map in TBB but it is…
1
vote
2 answers

All Common Subsequences in Array of Strings

I'm trying to find ALL common subsequences in an array of strings in ruby not just the longest single subsequence. This means that if the input is ["aaaF hello", "aaaG hello", "aaaH hello"] The expected output is ["aaa", " hello"] I've been…
1
vote
4 answers

Longest common substring constrained by pattern

Problem: I have 3 strings s1, s2, s3. Each contain garbage text on either side, with a defining pattern in its centre: text1+number1. number1 increases by 2 in each string. I want to extract text1+number1. I have already written code to find…
A T
  • 13,008
  • 21
  • 97
  • 158
1
vote
2 answers

Find longest substring without repeating characters (LeetCode)

I am trying to solve this problem on LeetCode (https://leetcode.com/problems/longest-substring-without-repeating-characters/) I got a code but i don't understand what's the problem with it. def lengthOfLongestSubstring(s): letters = [] …
AT Hill
  • 13
  • 2
1
vote
3 answers

Python function that finds the shortest string in a string list or the lowest element of an integer list

I'm doing this exercise: Write a Python program that gives two options to the user to either find the shortest string in a string list or the lowest element of an integer list. The program should read the two lists in both cases and handle any…
1
vote
2 answers

How to print the longest sentence from a column in a csv file

I am very new to python and am really struggling with this problem. I have a csv file with different columns, labeled "height" "weight" "full_name" etc. I'm trying to create a function that will look through the full_name column and return the…
Emppy
  • 15
  • 4
1
vote
0 answers

OCaml Longest common sequences (deep search)

Write with OCaml Longest Common Sottosequence (Deep Search) Consider a finite set S of strings and an integer K. Determine, if it exists, a string x of length greater than or equal to K subsequence of each string s∈S. The problem is solved by using…
1
vote
1 answer

Find the longest common substring from two sentences

My question is how to find the longest common substring from two sentences. For example: sequence 1 = "there were a dozen eggs in the basket" sentence 2 = "mike ate a dozen eggs for breakfast" The longest common substring from sentence 1 and…
mk6man
  • 43
  • 4
1
vote
0 answers

Problem with returning Nested function's value. Leetcode(Longest Palidromic Substring)

class Solution: def longestPalindrome(self, s: str) -> str: def is_palin(window: int, start: int) -> str: while window <= len(s) and start <= len(s) - window: print(f'window size : {window} start…
Sprout
  • 11
  • 3
1
vote
0 answers

Longest substring not working for repeating characters

I have a fairly standard moving window function to find longest substring. var lengthOfLongestSubstring = function (s) { let currentString = []; let longestStringLength = 0; let longestString = []; for (let i = 0; i < s.length; i++)…
Lewis
  • 135
  • 1
  • 10
1
vote
1 answer

Find character at which string can be differentiated from list of strings

For every string in a df column, I need the character at which this string becomes unique, that is, its uniqueness point (UP). For illustration, here is a toy dataframe: import pandas as pd import numpy as np df = pd.DataFrame({ 'word':['can',…
hyhno01
  • 177
  • 8
1
vote
0 answers

Memoization code for "Longest Common Substring" doesn't work as expected

I was able to think of a recursive solution for the problem "Longest Common Substring" but when I try to memoize it, it doesn't seem to work as I expected it to, and throws a wrong answer. Here is the recursive code. int lcs(string X, string Y,int…
1
vote
0 answers

XSLT Substring not woring

How to make XSLT substring-before second comma separate for example the separator is ',' ex : Aban, aban, 22, 33 so the result should be Aban, aban and following numbers in other elements.
1
vote
1 answer

The difference in application between SequenceMatcher in edit distance and that in difflib?

I know the implementation of the edit distance algorithm. By dynamic programming, we first fill the first column and first row and then the entries immediately right and below of the filled entries by comparing three paths from the left, above, and…
Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66
1
vote
1 answer

Get closest match between sentence(represented as string) and list of phrases

Let me start with an example. Consider the following list in python cities = [ 'New york' 'San francisco', 'California', 'Las vegas', 'Chicago', 'Miami' ] I also have following sentences. sentences = [ "Both of us were…
Ruchit
  • 336
  • 3
  • 16