compute Longest Common Prefix