burt_macklin_'s blog

By burt_macklin_, history, 5 years ago, In English
  • Vote: I like it
  • +3
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

First for each pair of string $$$(S1, S2)$$$, we find out the indices $$$\ 0 \leq i \leq S1.size ()\ $$$ such that $$$\ S1[i:]\ $$$ can overlap with $$$ S2[\ : min (\ S1.size() - i,\ S2.size())] $$$

Now it is always better to have one of the strings start from start of original string so we can do three checks with each string being the in start of the original string.

Then we can check all the possible start points for other $$$\ 2\ $$$ strings. The only problem being checking if some start position $$$\ i,\ j\ $$$ is okay in constant time. For each pair of string if they overlap we can check (using what we calculated in starting) if that overlap is fine.

I know My submission is not the cleanest way but still, happy to explain anything which is unclear.

»
5 years ago, # |
  Vote: I like it -8 Vote: I do not like it

There's editorial available for this task.