Longest Consecutive Login Streak
Problem statement
You are given a list of login records logins. Each record is [userId, date]: the user userId logged in on the day date, written as YYYY-MM-DD. The records can be in any order, and the same user can log in more than once on the same day.
A login streak of a user is a run of consecutive calendar days on which that user logged in at least once. If the user misses a day, the streak ends, and the next login starts a new streak. Several logins on one day count as one day.
Examples
Example 1
logins = [["ana","2026-05-03"],["ben","2026-05-03"],["ana","2026-05-04"],["ana","2026-05-06"],["ben","2026-05-04"],["ben","2026-05-05"],["ana","2026-05-07"],["ana","2026-05-08"]]return = 3ana logs in on May 3 and 4, misses May 5, then logs in on May 6, 7 and 8. Her longest run is May 6 to May 8, which is 3 days. ben logs in on May 3, 4 and 5, also 3 days. The answer is 3.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.