101
0/304
Loading content...
A fitness analytics team wants a stable trend metric that smooths noisy daily activity.
Table: Steps
Task: For each user, compute a 3-day rolling average of steps_count.
A row is included only when all of the following are true:
Output requirements:
Supported submission environments:
Steps:
| user_id | steps_count | steps_date |
|---------|-------------|-------------|
| 1 | 400 | 2024-01-01 |
| 1 | 600 | 2024-01-02 |
| 1 | 700 | 2024-01-03 |
| 1 | 500 | 2024-01-05 |
| 2 | 100 | 2024-02-10 |
| 2 | 200 | 2024-02-11 |
| 2 | 350 | 2024-02-12 |[
{"user_id":1,"steps_date":"2024-01-03","rolling_average":566.67},
{"user_id":2,"steps_date":"2024-02-12","rolling_average":216.67}
]User 1 qualifies on 2024-01-03 using Jan 1-3. Date 2024-01-05 is excluded because 2024-01-04 is missing. User 2 has one valid 3-day consecutive window ending on 2024-02-12.
Steps:
| user_id | steps_count | steps_date |
|---------|-------------|-------------|
| 3 | 1000 | 2024-03-01 |
| 3 | 900 | 2024-03-02 |
| 3 | 950 | 2024-03-03 |
| 3 | 1100 | 2024-03-04 |
| 3 | 1200 | 2024-03-05 |[
{"user_id":3,"steps_date":"2024-03-03","rolling_average":950.0},
{"user_id":3,"steps_date":"2024-03-04","rolling_average":983.33},
{"user_id":3,"steps_date":"2024-03-05","rolling_average":1083.33}
]With five consecutive days, three output rows are produced, one for each possible end date of a 3-day consecutive window.
Steps:
| user_id | steps_count | steps_date |
|---------|-------------|-------------|
| 7 | 800 | 2024-04-01 |
| 7 | 900 | 2024-04-02 |
| 8 | 500 | 2024-05-10 |
| 8 | 700 | 2024-05-12 |
| 8 | 900 | 2024-05-13 |[]No user has a full sequence of 3 consecutive calendar days, so the result is empty.
Constraints