Strings Problem

Revision en1, by jigsaw7, 2019-08-18 04:50:43

Given 2 strings S1 and S2 consisting of English letters.
For each index i in S1, it is required to find the largest index j >= i such that S1[i..j] is a substring of S2.

For example,
S1 = "acdsuaf"
S2 = "cadsua"
ans = [1, 2, 6, 6, 6, 6, -1].

How to approach this problem in linear time?

Tags #strings

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English jigsaw7 2019-08-18 04:50:43 373 Initial revision (published)