Longest Consecutive Identical Character Run
Problem statement
Given a string s, return the length of its longest nonempty consecutive run whose characters are all identical.
For this exercise, assume s contains only lowercase English letters and may be empty. Return 0 when s is empty.
Function
longestIdenticalRun(s: String) → intExamples
Example 1
s = "aaabbc"return = 3The prefix aaa is the longest identical-character run, so the answer is 3.
Example 2
s = "abbbbbaccc"return = 5The run bbbbb has length 5, longer than every other run.
Example 3
s = ""return = 0The empty string contains no nonempty run.
Constraints
scontains only lowercase English letters.smay be empty.