Fix if the end of the string is a part of the longest substring