Workout Streaks

ASKED IN INTERVIEW
4pts
Peloton

Problem Statement

Consistency is key to fitness. Peloton wants to reward its most dedicated users. A workout streak is defined as a series of consecutive days where the user completed at least one workout session.

Write an SQL query to find all user_ids who have achieved a workout streak of 10 days or more.

Rules:

  • A user must have at least one workout record on each day of the 10-day period.
  • Multiple workouts on the same day count as a single active day.
  • Only return a list of unique user_ids.
  • Output columns: user_id.
  • Sort the results by user_id in ascending order.

Table Schema:

  • Workouts: workout_id, user_id, workout_date (TIMESTAMP).
Tests your understanding of
Window Functions, DateTime, Gaps and Islands and Subqueries

Input Tables

Workouts
user_id(INTEGER)workout_date(TIMESTAMP)
12026-01-01 08:00:00
12026-01-02 09:00:00
12026-01-03 10:00:00
12026-01-04 07:00:00
12026-01-05 08:00:00
12026-01-06 09:00:00
12026-01-07 10:00:00
12026-01-08 11:00:00
12026-01-09 12:00:00
12026-01-10 08:00:00
22026-01-01 08:00:00
22026-01-03 08:00:00

Expected Output

user_id(INTEGER)
1

Tags

MediumASKED IN INTERVIEWWindow FunctionsDateTimeGaps and IslandsSubqueries
25-30 min
39%

Hints