HARDVerified Real Interview• Data Scientist / Growth

Consecutive Daily Login Streaks (Gaps & Islands)

Meta's Growth team rewards engaged users who achieve consecutive daily active streaks.

Write a SQL query using the classic Gaps & Islands technique (subtracting a row number from the login date) to find all users who maintained a streak of at least 3 consecutive calendar days. For each qualifying streak, return:

  • user_id
  • streak_start_date (earliest date in the continuous streak)
  • streak_end_date (latest date in the continuous streak)
  • streak_length_days (total consecutive days)

Sort by streak_length_days descending, then by user_id ascending.

Tables:

  • user_logins (user_id INT, login_date DATE)

Execution Sandbox:

Your query executes inside an isolated in-memory PostgreSQL engine (PGlite WebAssembly). You have full access to standard PostgreSQL aggregations, window functions, and CTEs.

Standard SQL (ANSI)|Ln 1, Col 1
⌘↵ Run Query
Ready to execute. Press Run (⌘+Enter)
Write your query and click “Run” or press ⌘+Enter to inspect output.