Find each user's longest login streak
On an online learning site daily logins are gamified: we track the longest run of consecutive days a user logged in. Logged in today and tomorrow — streak of two; missed a day — streak resets and starts over. For every user compute the length of their longest streak of consecutive login days. Sort by user id. Hint: if you spread dates by their position in the login order and subtract the position number, rows of the same streak land on the same offset — that's the «streak anchor» you can group by.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| user_id | longest_streak |
|---|---|
| 1 | 3 |
| 2 | 2 |
| 3 | 5 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in