SQL
All Top 50 SQL Interview Questions#35
Gaps and Islands: Detect 3+ Day Active Login Streaks in SQL
HardGoogleInterview Question #35
Asked at GoogleGiven `user_logins` (user_id, login_date), write a SQL query to find all users who logged in for at least 3 consecutive calendar days.
Input Table: user_logins
6 rows preview| user_id | login_date |
|---|---|
| 1 | 2026-03-01 |
| 1 | 2026-03-02 |
| 1 | 2026-03-03 |
| 1 | 2026-03-05 |
| 2 | 2026-03-01 |
| 2 | 2026-03-03 |
Expected Output Structure1 rows
| user_id | streak_start | streak_length |
|---|---|---|
| 1 | 2026-03-01 | 3 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.