solve longest common prefix