The other day we were writing sentences with my daughter with a fridge magnet letter. While we were able to make some(I love cat
), we didn't have enough letters to make the others (I love you too
) due to an insufficient amount of letters o
(4)
I then found out that while one set included 3 e
letters it had only 2 o
letters. Probably inspired by http://en.wikipedia.org/wiki/Letter_frequency this would still not reflect the actual situation "on the fridge".
Problem
Given the text file where each line contains a "sample sentence" one would want to write on the fridge, propose an alphabet set with minimum amount of letters but still sufficient to write each sentence individually.
Note: ignore cases, all magnet letters are capitals anyway.
Input
The file contain newline separated sentences:
hello
i love cat
i love dog
i love mommy
mommy loves daddy
Output
Provide back sorted list of letters, where each letter appears only as many times to be sufficient to write any sentence:
acdddeghillmmmoostvyy
(thanks, isaacg!)
Winner
Shortest implementation (code)
UPDATED: Testing
I have created an extra test and tried with various answers here:
v
in the output ;) \$\endgroup\$M
for aW
, or a sidewaysN
for aZ
? ;-) \$\endgroup\$I
s. \$\endgroup\$_\¯
\$\endgroup\$