Interview Query

Common Prefix

2
Have you seen this question before?

Given a list of strings, write a function that returns their longest common prefix. For example, if you were given the strings “flowers”, “flow”, and “flight”, your function should return the string “fl”.

If the list of strings has no common prefix, return an empty string.

Example 1:

Input:

strings = ["flowers", "flow", "flight"] 

Output:

"fl"

Example 2:

Input:

strings = ["showboat", "showcase", "shower"]

Output:

"show"
Next question: Experiment Validity
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code