I need to find longest common substring with greatest (length of substring * count).
For example, when I have string:
hi, hello world ... hello world ... hi, hello world
The answer is hello world
, because (11 * 3) > (15 * 2).
I have found a relevant discussion in this question, but it is not practical to use in my case, because of its high memory usage.
Is there any better way how to do that?