Common string prefix
Return the longest prefix shared by every string. Return an empty string for no strings.
prefix = 'flower'
while not 'flow'.startswith(prefix):
prefix = prefix[:-1]
print(prefix)Reason about the state
Shrink a candidate prefix until every string starts with it. Once empty it cannot grow again; stop immediately. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the longest prefix shared by every string. Return an empty string for no strings.
The explanation opens here once every check passes.