Longest Win Streak
Medium · rating 1100 · strings
A team's season is recorded as a string of W (win) and L (loss) characters. Read the string and print the length of the longest streak of consecutive wins.
Editorial
Longest Win Streak finds the longest run of consecutive Ws in a season string — a classic run-length scan. Keep a current-streak counter that resets on every loss, tracking the maximum seen.
best = cur = 0
for c in s:
cur = cur + 1 if c == 'W' else 0
best = max(best, cur)
print(best)Complexity
Time: O(n). Space: O(1).