How to find all intersections (also called the longest common substrings) of two strings and their positions in both strings?
For example, if S1="never" and S2="forever" then resulted intersection must be ["ever"] and its positions are [(1,3)]. If S1="address" and S2="oddness" then resulted intersections are ["dd","ess"] and their positions are [(1,1),(4,4)].
Shortest solution without including any library is preferable. But any correct solution is also welcomed.
Well, you’re saying that you can’t include any library. However, Python’s standard difflib contains a function which does exactly what you expect. Considering that it is a Python interview question, familiarity with difflib might be what the interviewer expected.
You can always ignore the last Match tuple, since it’s dummy (according to documentation).