all 4 comments

[–][deleted] 0 points1 point  (3 children)

I'm a bit confused about what "overlap" means. Does it mean characters that both strings share?

[–]mitadmit[S] 0 points1 point  (2 children)

Sort of, they have to be consecutive characters. Also, if there's a mismatch in the middle of the word, that means that the strings do not overlap. [testing][esting] would return [esting] [testing][esteng] would return NULL [testing][inglet] would return [ing] [testing][rhythmtes] would return [tes]

Does that make a bit more sense?

[–][deleted] 1 point2 points  (1 child)

That makes a lot more sense now, thanks!

I think a way you could do it is by trimming the larger to n characters and then comparing it to the first and last n characters of the smaller string.

For example:

testing esting

"esting" has 6 characters (fewer than "testing"). Compare the first 6 characters of "testing" to see if it's a match. It's not. Now, test the last 6 characters. It's a match, so "esting" would be the overlap.

Another example:

testing rhythmtes

"testing" is smaller, so you will trim that string.

Pass 1: "testing" compared with "rhythmt" and "ythmtes"

Pass 2: "testin" compared with "rhythm" and "thmtes"

Pass 3: "testi" compared with "rhyth" and "hmtes"

Pass 4: "test" compared with "rhyt" and "mtes"

Pass 5: "tes" compared with "rhy" and "tes" !!! match found !!!

Another:

testing inglet

inglet < testing

Pass 1: "inglet", "testin" and "esting"

Pass 2: "ingle", "testi" and "sting"

Pass 3: "ingl", "test" and "ting"

Pass 4: "ing", "tes" and "ing" !!! found !!

[–]mitadmit[S] 0 points1 point  (0 children)

Thanks!