Python data engineering interview problem. Difficulty: beginner. Pattern: Strings. About 8 minutes. Part of the Pro drill bank.
Find the longest string that every word starts with. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement lcp(words: list[str]) -> str that returns the longest prefix shared by all the words. Return "" when there is no common prefix or when the list is empty.
Input: lcp(["flower", "flow", "flight"]) Output: 'fl' All three start with 'fl'; the third letter differs.
Topics: lakebench, python, prefix, strings.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Find the longest string that every word starts with.
Implement `lcp(words: list[str]) -> str` that returns the longest prefix shared by all the words. Return `""` when there is no common prefix or when the list is empty.