A relay station keeps a transmission log as a string of lowercase letters, one letter per time slot, where each letter names the signal code the station broadcast during that slot. Engineers care about steadiness: the longest unbroken run of consecutive time slots during which the exact same signal code was broadcast, over and over, without interruption.
Given the log, report the length of its longest steady run.
Example 1
Input
aabbbcc
Expected
3
Explanation
The runs of identical consecutive characters are 'aa' (length 2), 'bbb' (length 3), and 'cc' (length 2). The longest is 'bbb', so the answer is 3.
Example 2
Input
xxxxyzzzzzzq
Expected
6
Explanation
The runs are 'xxxx' (length 4), 'y' (length 1), 'zzzzzz' (length 6), and 'q' (length 1). The longest is 'zzzzzz', so the answer is 6.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →