Find Users With Overlapping Invites and Disjoint Confirmed Meetings
Company: Zoom
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Return the `user_id` of every user who satisfies both of these conditions:
- The user was invited (any `status`) to at least two overlapping meetings. Two meetings overlap when their time ranges intersect, meaning each one starts before the other ends.
- The user has `status = 'confirmed'` in at least two disjoint meetings. Two meetings are disjoint when one ends at or before the other starts.
```hint Working with pairs
Each condition is a statement about a pair of different meetings for the same user. Think about how to produce each such pair once, and check the two conditions separately.
```
### Input Table(s)
`meetings`
| Column | Type | Meaning |
|---|---|---|
| meeting_id | INT | Meeting identifier. Primary key. |
| title | VARCHAR(255) | Meeting title. Not null. |
| start_time | TIMESTAMP | Start time. Not null. |
| end_time | TIMESTAMP | End time. Not null, always after `start_time`. |
`participation`
| Column | Type | Meaning |
|---|---|---|
| id | INT | Row identifier. Primary key. |
| user_id | INT | Invited user. Not null. |
| meeting_id | INT | Meeting the user was invited to, matching `meetings.meeting_id`. Not null. |
| status | VARCHAR(50) | One of `'confirmed'`, `'declined'`, `'pending'`. Not null. |
Keys: `meetings.meeting_id` and `participation.id` are primary keys. A user is invited to the same meeting at most once, so (`user_id`, `meeting_id`) is unique in `participation`.
### Output Contract
- One column: `user_id`.
- One row per qualifying user, with no repeats.
- Order by `user_id` ascending.
- Return an empty result if no user qualifies.
### Example
`meetings`
| meeting_id | title | start_time | end_time |
|---|---|---|---|
| 1 | Standup | 2024-03-01 09:00:00 | 2024-03-01 09:30:00 |
| 2 | Design review | 2024-03-01 09:15:00 | 2024-03-01 10:00:00 |
| 3 | Planning | 2024-03-01 10:00:00 | 2024-03-01 11:00:00 |
| 4 | Retro | 2024-03-01 13:00:00 | 2024-03-01 14:00:00 |
`participation`
| id | user_id | meeting_id | status |
|---|---|---|---|
| 1 | 1 | 1 | confirmed |
| 2 | 1 | 2 | pending |
| 3 | 1 | 3 | confirmed |
| 4 | 2 | 1 | confirmed |
| 5 | 2 | 2 | confirmed |
| 6 | 3 | 2 | confirmed |
| 7 | 3 | 3 | confirmed |
| 8 | 3 | 4 | declined |
| 9 | 4 | 1 | declined |
| 10 | 4 | 2 | declined |
| 11 | 4 | 3 | confirmed |
| 12 | 4 | 4 | confirmed |
Expected output:
| user_id |
|---|
| 1 |
| 4 |
Meetings 1 and 2 are the only overlapping pair. Meeting 2 ends at 10:00, exactly when meeting 3 starts, so those two are disjoint, and every other pair is disjoint as well.
- User 1 was invited to meetings 1 and 2, which overlap, and confirmed meetings 1 and 3, which are disjoint. User 1 qualifies.
- User 2 confirmed meetings 1 and 2, but that pair overlaps, so user 2 has no confirmed disjoint pair.
- User 3 confirmed meetings 2 and 3, which are disjoint, but none of user 3's meetings overlap.
- User 4 declined meetings 1 and 2. Declined invitations still count for the first condition, and user 4 confirmed meetings 3 and 4, which are disjoint. User 4 qualifies.
### Constraints and Clarifications
- Each table has at most 10,000 rows.
- `status` is one of `'confirmed'`, `'declined'`, `'pending'`.
- `start_time` is strictly before `end_time`.
- A user is invited to the same meeting at most once.
- Both meetings in a pair must be different meetings. Two different meetings with identical times overlap.
- Meetings that only touch (one ends at the moment the other starts) do not overlap and count as disjoint.
- The two conditions are independent. The same meeting may count toward both, as meeting 1 does for user 1 above.
Overview: Write a SQL query that returns users who were invited to two overlapping meetings and also confirmed two meetings that do not overlap. It tests self-joins over pairs of meetings, interval logic at shared boundaries, and combining two sets of users.