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?