SQLSQL
#35

Gaps and Islands: Detect 3+ Day Active Login Streaks in SQL

HardGoogle
Interview Question #35
Asked at Google

Given `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_idlogin_date
12026-03-01
12026-03-02
12026-03-03
12026-03-05
22026-03-01
22026-03-03
Expected Output Structure1 rows
user_idstreak_startstreak_length
12026-03-013
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us