You don't really need complex Trie methods : Simple sorting approach


#1

def longestCommonPrefix(self, array):

    array.sort()

    count = 0
    for i in range(min(len(array[0]),len(array[-1]))):
        if array[0][i] == array[-1][i]:
            count+=1
    res=array[0]

    return res[:count]

#2

Hi!
what if the input will be:
[‘aaa’, ‘abcd’, ‘aaaaa’]
?
the prefix should be ‘a’
but ur program will return ‘aaa’