Write a program or function that takes in a string of words and return or print the word with the most repeating single letters.
Choose the word with the greatest number of repeating single letters (see examples below)
If no word has repeating letters, return -1.
If two words have the same maximum number of repeating letters, choose the one closer to the start of the string.
The shortest submission in bytes wins.
Take as input a string consisting of one or more space-delimited words. Input can be from STDIN (or closest alternative), command line parameters, or function arguments.
Print the output to STDOUT to return it.
Consider the string
aaabbb cccc. This contains two words:
cccc. The word
aaabbb has 3
a's and 3
cccc has 4
c's. So the maximum number of repeated letters in
aaabbb is 3 and the maximum in
cccc is 4. We want to choose the word with the maximum number of repeated single letters, so the output for
aaabbb cccc should be
Other test cases:
Today, is the greatest day ever! --> greatest This is a great day --> -1 aaabbb cccc --> cccc