CJCoding With Joseph
15free / daySign inCreate account

Longest Run Of One Letter

Read one word and print the length of its longest run, where a run is the same character repeated side by side, in the form Longest run: <n>; a word with no repeated neighbours has a longest run of 1. Keep three values as you walk the word from its second character onwards with a for loop over the slice [1:]: the current run length, the best run seen so far, and the previous character; extend the run when the character equals the previous one, otherwise restart it at 1, update the best whenever the run beats it, and remember the character for the next pass. Input: one line, a word of at least one character, no prompt.

Expected Output:

Longest run: 3

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Strings
📥 Auto-Input:
aabbbcc\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.