You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a function to find the longest common prefix string amongst an array of strings.
'''
from __future__ importdivision
importrandom
### Solution#1: Build a trie tree: O(nm)
### Solution#2: Hash the first string as f, fl, flo, flow, flowe, flower, and initialize the max_prefix_len=5.
# For every other string s, start checking the prefix with min{max_prefix_len, len(s)}. If match go to the next string; if not, remove the last character and re-compare. ~O(n+m)