Problem 135419 · medium · Phase 01 Prerequisites & Setup

Longest Streak

lists · loops · adjacent-comparison

A team's season is a list of results such as "W" or "L" (any values will do). Write longest_streak(results) that returns the length of the longest run of consecutive equal values. Return 0 for an empty list.

Examples

Input:  results = ["W", "W", "L", "W", "W", "W", "L"]
Output: 3

Input:  results = []
Output: 0

Constraints

  • 0 <= len(results) <= 5000

Goals

  • Compare each item with the previous one
  • Track a current run and the best run seen
Starting Python…