Current Daily-Login Streak

Hard ⏱ 18 min 26% acceptance ★★★★☆ 4.4
Write streak(dates, today) where dates is a set of login dates. Count the current streak ending at today: if today is present, count backwards day by day while dates are present. If today is absent the streak is 0.

Examples

Example 1
Input
streak({date(2026,7,26), date(2026,7,27), date(2026,7,28)}, date(2026,7,28))
Output
3
Explanation

Three consecutive days ending today.

Constraints

  • Streak requires today itself.
  • Walk backwards with timedelta.

Topics

Date & Timestreak logic

Companies

DuolingoSnapchatMeta

Hints

Hint 1

while current in dates: count and step back one day.

Hint 2

Start current at today.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.