Given a string containing only letters, output the length of the longest run of consecutive alphabetical letters the word contains, where order does not matter. An example algorithm may sort the word, remove duplicates, and then output the length of the longest run.

Test Cases

watch -> 1
stars -> 3
antidisestablishmentarianism -> 3
backdoor -> 4
a -> 1
tutorials -> 4

For example, antidisestablishmentarianism contains the letters abdehilmnstr. The longest runs are lmn and rst, both of length 3.


You may take all lowercase, all uppercase, or mixed-case letters as input, but the case cannot encode information about the word (i.e. you cannot make the first n characters capitalized where n is the length of the longest run).

This is , so shortest answer in bytes wins.

  • \$\begingroup\$ @H.PWiz, I'm guessing that's a typo and it should be rst - uniquify, sort and get longest consecutive run. Can we take input as an array of characters? \$\endgroup\$
    – Shaggy
    Jul 11 '18 at 21:46
  • \$\begingroup\$ @Shaggy yes, definitely, I didn't include it because I thought it was a default \$\endgroup\$
    – Stephen
    Jul 11 '18 at 21:51
  • \$\begingroup\$ Is 'a' adjacent to 'z' -- should 'zebra' score 2 or 3? \$\endgroup\$ Jul 11 '18 at 21:54
  • \$\begingroup\$ (...judging by your example algorithm I guess "no" and "2") \$\endgroup\$ Jul 11 '18 at 22:00
  • \$\begingroup\$ @JonathanAllan you are correct \$\endgroup\$
    – Stephen
    Jul 11 '18 at 22:05

31 Answers 31


Husk, 7 bytes


Try it online!

First time I've used simil(≈), and it works really well!


     Ou order and deduplicate
   ġ≈   group by absolute difference ≤ 1
 ►L     max by length
L       take the length of that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.