Brainlag
  1. Library
  2. Challenges
  3. Python

Longest win streak

Given a season of match results, find the longest run of wins in a row.

PythonWarm-up15 min

Write longest_streak(results). results is a list of "W" (win) and "L" (loss) in match order. Return the length of the longest run of "W" in a row. A season with no wins returns 0.

Python
longest_streak(["W", "W", "L", "W", "W", "W", "L"])   # 3

Checks

  1. A streak in the middle
  2. Edges and empty seasons
exercise_1.py to run
def longest_streak(results):
    pass

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.