Loading content...
A retail analytics team records each customer check-in date in a visit log table. They want to measure the longest inactivity span per user so retention programs can prioritize users with large gaps between visits.
Table: user_visits
Data characteristics:
Reference date:
Task: For each user_id, compute the maximum number of days between:
Output requirements:
Supported submission environments:
user_visits:
| user_id | visit_date |
|---------|-------------|
| 1 | 2020-11-28 |
| 1 | 2020-10-20 |
| 1 | 2020-12-03 |
| 2 | 2020-10-05 |
| 2 | 2020-12-09 |
| 3 | 2020-11-11 |[
{"user_id":1,"biggest_window":39},
{"user_id":2,"biggest_window":65},
{"user_id":3,"biggest_window":51}
]For user 1, sorted visits are 2020-10-20, 2020-11-28, 2020-12-03. Gaps are 39, 5, and 29 days to the anchor date; max is 39.
user_visits:
| user_id | visit_date |
|---------|-------------|
| 10 | 2020-12-25 |
| 10 | 2020-12-25 |
| 10 | 2020-12-31 |
| 20 | 2020-01-01 |
| 20 | 2020-06-01 |[
{"user_id":10,"biggest_window":6},
{"user_id":20,"biggest_window":152}
]Duplicate same-day visits are valid. For user 10, the largest gap is from 2020-12-25 to 2020-12-31 (6 days). For user 20, largest gap is 152 days from 2020-01-01 to 2020-06-01.
user_visits:
[][]If there are no visit records, there are no users to report.
Constraints