Loading problem...
A retail intelligence team wants to flag customers who come back quickly after a previous purchase.
Table: Purchases
A user is considered a rapid repeat buyer if they have at least one pair of purchases where the later purchase happened within 7 calendar days of the earlier one. Same-day purchases also qualify.
Task: Return all qualifying user IDs.
Output requirements:
Supported submission environments:
Purchases:
| purchase_id | user_id | purchase_date |
|-------------|---------|---------------|
| 1 | 10 | 2024-01-01 |
| 2 | 10 | 2024-01-08 |
| 3 | 20 | 2024-01-01 |
| 4 | 20 | 2024-01-20 |
| 5 | 30 | 2024-01-05 |
| 6 | 30 | 2024-01-05 |[
{"user_id":10},
{"user_id":30}
]User 10 qualifies because Jan-08 is exactly 7 days after Jan-01. User 30 qualifies because same-day pairs count. User 20 does not qualify because the gap is 19 days.
Purchases:
| purchase_id | user_id | purchase_date |
|-------------|---------|---------------|
| 101 | 5 | 2024-02-01 |
| 102 | 5 | 2024-02-10 |
| 103 | 6 | 2024-02-02 |
| 104 | 6 | 2024-02-04 |
| 105 | 6 | 2024-02-25 |[
{"user_id":6}
]User 6 has a 2-day gap between Feb-02 and Feb-04. User 5 has only a 9-day gap and does not qualify.
Purchases:
| purchase_id | user_id | purchase_date |
|-------------|---------|---------------|
| 201 | 1 | 2024-03-01 |
| 202 | 2 | 2024-03-02 |
| 203 | 3 | 2024-03-03 |[]Every user has only one purchase, so no user can form a qualifying pair.
Constraints