Given an array of strings, create abbreviated versions of each string.
For this challenge, an abbreviation is the first N characters of a string. For the string
abc are all valid abbreviations, while
ac are not.
Given an array of strings, we want to find the shortest set of abbreviations, such that given the input and any abbreviation, you could determine which item of the input that the abbreviation was referring to.
["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
We work our way through the strings starting with the first one.
Monday is only the item string with an
M, so the shortest possible abbreviation is
Tuesday starts with
T, but so does Thursday. This means that we try the string
TU. Since no other strings start with that, we use
W, Thursday is
Th, and Friday is
Input: "one,two,three,four,five,six,seven" Output: "o,tw,th,fo,fi,si,se" Input: "red,orange,yellow,green,blue,purple" Output: "r,o,y,g,b,p" Input: "a,ab,abc" Output: Not valid! No abbreviation for `a` that doesn't apply to the other items.
You make input and output in any reasonable way.
You can assume that input will always be a valid array of strings.
You can assume that there will always be a solution, unlike in the last test case.
Strings will only consist of printable ASCII (or the printable characters in your encoding)
This is code golf, so fewest bytes win!