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
In the event that an empty list, a list containing one string, or a list of strings with no common prefixes is passed, the empty string will be returned.
9
9
"""
10
+
ifnotstringsorlen(strings) ==1:
11
+
return""
12
+
10
13
longest=""
11
-
forstring_index, stringinenumerate(strings):
12
-
forother_stringinstrings[string_index+1:]:
13
-
common=find_common_prefix(string, other_string)
14
-
iflen(common) >len(longest):
15
-
longest=common
14
+
15
+
# Precompute: Build a dictionary of prefixes to their count
16
+
# For each string, generate all its prefixes and count occurrences
17
+
prefix_count= {}
18
+
19
+
forstringinstrings:
20
+
seen_prefixes=set() # Avoid counting same prefix twice from same string
0 commit comments