Longest common substring and string permutations