solution to longestCommonPrefix