15
1
Inspired by this wonderful (based on the number of views and votes) challenge, which, in my humble opinion, has way too few answers.
Given (by any means) a list of strings, return (by any means) a set of letters that, when removed from the given strings, leaves the total length of (what remains of) the strings as small as possible, while keeping each string unique and at least one character long.
Examples:
Given "Day" and "day"; return "ay", because the given strings will be "D" and "d" when the characters "ay" are removed.
Given "Hello World!", "Hello world.", and "Hello world"; return "Helo Wrd" gives because the strings will be "!", "w.", and "w" when the characters "Helo Wrd" (with a space) are removed.
Given "century", "decade", "year", "month", "week", "day", "hour", "minute", and "second"; return "centurdowi" because the given words will be "y", "a", "ya", "mh", "k", "ay", "h", "m", "s" when the characters "centurdowi" are removed.
The order and format of the returned set is not important.
1Your second case is wrong: "Helo Wrd" gives a total length of 4 with "!", "w." and "w". – Luke – 2015-12-21T20:26:29.050
1@Luke Thanks. I'll fix that. That shows that we need an algorithm, as doing it by hand is error prone. – Adám – 2015-12-21T20:31:19.400
And for the third one, 'centurdowi' yields 'y', 'a', 'ya', 'mh', 'k', 'ay', 'h', 'm', 's' for a total length of 12. – Luke – 2015-12-21T20:44:19.680
@Luke Thanks.
– Adám – 2015-12-21T20:54:59.700+1 for using a challenge to help you in another challenge! – Luke – 2015-12-21T21:29:12.877
Test case: input ['CAB','FED'] output '' or "CAFE"? – edc65 – 2015-12-22T13:59:18.847
@edc65 'CAFE' or any equivalent ('ABED'...). OP: "keeping each string unique and at least one character long" – Adám – 2015-12-22T16:25:49.317
@nbz each string is unique and at least one character long from start in my example – edc65 – 2015-12-22T18:53:45.327
@edc65 "leaves the total length of (what remains of) the strings as small as possible," – Adám – 2015-12-23T02:15:11.113