20
6
The program must output the letter that is paired the most. For example, if your program was given the following string:
"Sally's friend Bobby searched for seashells."
it must output L
because "ll"
occurs twice, which is more frequent than the other pair "bb"
.
Rules:
- If more than one letter has 1st place for occurrences, then output all of them in alphabetical order (e.g.
"Sally's friends Jimmy and Bobby rummaged for seashells."
should output bothL
ANDM
[or"LM"
if you please] because they both occur more frequently than other pairs.) - Letters which are tripled, quadrupled, etc. count as one pair (e.g.
"lll"
in"willless"
is counted as only one pair ofL
.) - Letter pairs must be in one word (e.g.
"Sally's sociable friends Sammy and Bobby searched for fabulous seashells."
should outputL
and notS
because despite"ss"
having more occurrences than"ll"
, they are separated by spaces.) - Count only letters from the English alphabet
- Case does not matter (e.g.
"Ss"
is the same as"SS"
or"ss"
, and all are counted as one pair ofS
.)
You may read your input from wherever you please. Shortest code wins.
2Can we assume that only letters will occur in pairs or could the input contain double spaces or double
'
etc? – Martin Ender – 2015-07-01T22:37:59.7071Can we assume that at least one letter appears twice? – Martin Ender – 2015-07-01T22:40:20.540
@MartinBüttner Yes, you can assume at least one letter pair occurs. However, other characters may appear in pairs as well. Only count letters. – ayane – 2015-07-01T23:24:10.193
Even if there is only one pair, can I still print it in a list like
['l']
? – Maltysen – 2015-07-02T01:28:09.100@Maltysen Yes, you may do so. – ayane – 2015-07-02T02:18:41.747
Fun challenge. My main suggestion would be to add some more tests. For example: Mix of upper/lower case for repeated letters. Tripled/quadrupled letters. Non-letter character is the most repeated. – Reto Koradi – 2015-07-02T06:13:15.417
@AlexA. It says "output all of them in alphabetical order". – Reto Koradi – 2015-07-02T21:06:07.990
@RetoKoradi: Sorry, missed that. Thanks. – Alex A. – 2015-07-02T21:10:49.757