101
0/304
Loading content...
A product analytics team records bounded user sessions in a table and needs a one-row recency snapshot per account.
Table: user_activity
Data characteristics:
Task: For each username, return exactly one activity interval:
Recency rule:
Output requirements:
Supported submission environments:
user_activity:
| username | activity | start_date | end_date |
|----------|----------|------------|------------|
| Alice | Travel | 2020-02-12 | 2020-02-20 |
| Alice | Dance | 2020-02-21 | 2020-02-23 |
| Alice | Travel | 2020-02-24 | 2020-02-28 |
| Bob | Travel | 2020-02-11 | 2020-02-18 |[
{"username":"Alice","activity":"Dance","start_date":"2020-02-21","end_date":"2020-02-23"},
{"username":"Bob","activity":"Travel","start_date":"2020-02-11","end_date":"2020-02-18"}
]Alice has three unique intervals, so we return the second latest by start_date. Bob has one unique interval, so we return it.
user_activity:
| username | activity | start_date | end_date |
|----------|----------|------------|------------|
| Nora | Browse | 2023-01-01 | 2023-01-02 |
| Nora | Browse | 2023-01-01 | 2023-01-02 |
| Nora | Purchase | 2023-01-05 | 2023-01-06 |[
{"username":"Nora","activity":"Browse","start_date":"2023-01-01","end_date":"2023-01-02"}
]Duplicate rows are treated as the same unique interval. Nora has two unique intervals, so we return the older one among the top two.
user_activity:
| username | activity | start_date | end_date |
|----------|----------|------------|------------|
| Kai | Login | 2024-03-09 | 2024-03-09 |
| Kai | Search | 2024-03-10 | 2024-03-10 |
| Kai | Search | 2024-03-10 | 2024-03-10 |
| Mira | View | 2024-05-01 | 2024-05-02 |[
{"username":"Kai","activity":"Login","start_date":"2024-03-09","end_date":"2024-03-09"},
{"username":"Mira","activity":"View","start_date":"2024-05-01","end_date":"2024-05-02"}
]Kai's latest unique interval is Search, so the second latest is Login. Mira has only one interval.
Constraints