101
0/304
Loading content...
A product analytics team wants to detect consistently engaged users from raw authentication events.
Table: accounts
Table: logins
Definition: A user is considered active when they logged in on at least 5 consecutive calendar days.
Important semantics:
Task: Return all active users.
Output requirements:
Supported submission environments:
accounts:
| id | name |
|----|----------|
| 1 | Winston |
| 7 | Jonathan |
| 9 | Mira |
logins:
| id | login_date |
|----|------------|
| 7 | 2020-05-30 |
| 1 | 2020-05-30 |
| 7 | 2020-05-31 |
| 7 | 2020-06-01 |
| 7 | 2020-06-02 |
| 7 | 2020-06-02 |
| 7 | 2020-06-03 |
| 1 | 2020-06-07 |
| 7 | 2020-06-10 |[
{"id":7,"name":"Jonathan"}
]User 7 has a five-day streak from 2020-05-30 to 2020-06-03. Duplicate rows on 2020-06-02 do not increase streak length.
accounts:
| id | name |
|----|------|
| 10 | Ava |
| 11 | Ben |
| 12 | Cara |
logins:
| id | login_date |
|----|------------|
| 10 | 2024-01-28 |
| 10 | 2024-01-29 |
| 10 | 2024-01-30 |
| 10 | 2024-01-31 |
| 10 | 2024-02-01 |
| 11 | 2024-03-01 |
| 11 | 2024-03-03 |
| 11 | 2024-03-04 |
| 11 | 2024-03-05 |
| 11 | 2024-03-06 |
| 12 | 2024-06-10 |
| 12 | 2024-06-10 |
| 12 | 2024-06-11 |
| 12 | 2024-06-12 |
| 12 | 2024-06-13 |
| 12 | 2024-06-14 |[
{"id":10,"name":"Ava"},
{"id":12,"name":"Cara"}
]User 10 has a streak crossing a month boundary. User 12 qualifies despite duplicates. User 11 misses because 2024-03-02 is absent.
accounts:
| id | name |
|----|------|
| 21 | Noor |
| 22 | Sam |
| 23 | Theo |
logins:
| id | login_date |
|----|------------|
| 21 | 2020-02-27 |
| 21 | 2020-02-28 |
| 21 | 2020-02-29 |
| 21 | 2020-03-01 |
| 21 | 2020-03-02 |
| 22 | 2020-12-29 |
| 22 | 2020-12-30 |
| 22 | 2020-12-31 |
| 22 | 2021-01-01 |
| 23 | 2021-01-05 |
| 23 | 2021-01-06 |
| 23 | 2021-01-07 |
| 23 | 2021-01-08 |
| 23 | 2021-01-09 |[
{"id":21,"name":"Noor"},
{"id":23,"name":"Theo"}
]Leap-day and year transitions are handled as normal calendar days. User 22 has only four consecutive days.
Constraints