Given a list of strings, replace each string by one of its non-empty substrings which is not a substring of any of the other strings in the list and as short as possible.
Example
Given the list ["hello","hallo","hola"]
, "hello"
should be replaced by just "e"
as this substring is not contained in "hallo"
and "hola"
and it is as short as possible. "hallo"
could be replaced by either "ha"
or "al"
and "hola"
by any of "ho"
, "ol"
or "la"
.
Rules
- You can assume that the strings will be non-empty and only contain alphabetical characters of the same case.
- You can assume that such a substring exists for each string in the list, i.e. no string in the list will be a substring of any of the other strings.
- Input and output can be in any reasonable format.
- This is code-golf, so try to use as few bytes as possible in the language of your choice.
Test Cases
Only one possible output is given for most cases.
["ppcg"] -> ["p"] (or ["c"] or ["g"])
["hello","hallo","hola"] -> ["e","ha","ho"]
["abc","bca","bac"] -> ["ab","ca","ba"]
["abc","abd","dbc"] -> ["abc","bd","db"]
["lorem","ipsum","dolor","sit","amet"] -> ["re","p","d","si","a"]
["abc","acb","bac","bca","cab","cba"] -> ["abc","acb","bac","bca","cab","cba"]
Related: Shortest Identifying Substring - similar idea, but more involved rules and cumbersome format.
""
(empty string) uniquely identifying for the single"ppcg"
case? \$\endgroup\$