Longest Daily Streak

Python for AIHard+10 XP+10

Longest Daily Streak

A language app records each day a learner practised, as text like "2026-03-14".

Task: write longest_streak(days) that returns the length of the longest run of back-to-back calendar days.

  • The list is not sorted, and the same day may appear more than once (practising twice in a day still counts as one day).
  • Runs can cross the end of a month or a year, and leap days count.
  • An empty list returns 0.

28 February, 1 March and 2 March are back-to-back (2026 is not a leap year).

Examples

days = ["2026-03-02", "2026-03-01", "2026-02-28", "2026-03-05", "2026-03-01"]
returns 3
days = ["2026-07-04"]
returns 1

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run