Continue learning
Practice related DSA questions in the same topic.
Find the length of the longest uninterrupted run of equal lowercase letters.
Find the length of the longest uninterrupted run of equal lowercase letters.
def solve(values, target): run = 0 best = 0 i = 0 while (i < len(values)): if ((i > 0) and (values[i] == values[(i - 1)])): run = (run + 1) else: run = 1 best = max(run, best) i = (i + 1) return bestCheck whether the character continues the current run of 0.
Check whether the character continues the current run of 0.
A winning streak ends as soon as the jersey colour changes.
Only an equal neighbour extends the current run; any change starts length one.
O(n) time · O(1) auxiliary space
Worked example · {"values":[1,1,2,2,2,1],"target":0} ⇒ 3
Edge case 1 · {"values":[],"target":0} ⇒ 0
Edge case 2 · {"values":[4],"target":0} ⇒ 1
Counting all copies combines runs that a different character separates.
How would you return the letter and first position of a longest run?