Solve longest common substring problem