As reported: Target Data Engineer interview (2025), round 1: after the SQL question, a Python question — the longest common prefix of a list of strings (e.g.
['abcd', 'abc', 'abcdef']).
This is LeetCode 14 — Longest Common Prefix. Our write-up: /longest-common-prefix.
Write a function that finds the longest common prefix string among an array of strings. If there is no common prefix, return an empty string "".
Example 1
strs = ["flower","flow","flight"]
Output: "fl"
Example 2
strs = ["dog","racecar","car"]
Output: ""
Example 3
strs = ["abcd","abc","abcdef"]
Output: "abc"
Constraints: 1 ≤ strs.length ≤ 200; 0 ≤ strs[i].length ≤ 200; strs[i] consists of only lowercase English letters if it is non-empty.
Code runner format: one JSON line: strs. Implement longestCommonPrefix(strs).