resolve the longest common prefix