Shared SKU Prefix
easyA warehouse labels products with SKU strings, and codes from the same supplier share a leading stem — "FORGE-ANVIL-01", "FORGE-ANVIL-02", "FORGE-TONGS-01" all start with "FORGE-". Given a batch of codes, the intake scanner wants that stem.
Return the longest common prefix of all strings in codes. If they share nothing, return the empty string "".
Example 1
in codes = ["flower", "flow", "flight"]
out "fl"
All three open with "fl"; the third letter diverges (o vs i).
Example 2
in codes = ["dog", "racecar", "car"]
out ""
No shared first letter, so no shared stem at all.
Constraints
- · 1 <= len(codes) <= 200
- · 0 <= len(codes[i]) <= 200
- · codes[i] consists of printable ASCII characters
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.