Shortest Unique Substring
viaLeetCode
Shortest Unique Substring. Given a list of names (strings), for each name find the shortest contiguous substring that appears in that name and in no other name in the list. If several shortest substrings exist, any one is acceptable.
Input: ["cheapair", "cheapoair", "peloton", "pelican"]
Output:
"cheapair": "pa"
"cheapoair": "po" // "oa" also acceptable
"pelican": "ca" // "li", "ic", or "an" also acceptable
"peloton": "t" // single letter not occurring in any other string
asked …