Given a table of phone calls, find users whose first and last calls on any day were with the same person.
The Calls table contains:
caller_id: ID of the person making the callrecipient_id: ID of the person receiving the callcall_time: Timestamp of the call
A call involves both participants equally - whether someone is the caller or recipient, it counts as their call with that person.
Return the IDs of users whose first and last calls on the same day were with the same person.
Table Schema
| Column Name | Type | Description |
|---|---|---|
caller_id
PK
|
int | ID of the person making the call |
recipient_id
PK
|
int | ID of the person receiving the call |
call_time
PK
|
datetime | Timestamp when the call occurred |
Input & Output
| caller_id | recipient_id | call_time |
|---|---|---|
| 1 | 2 | 2024-07-09 09:00:00 |
| 1 | 3 | 2024-07-09 17:00:00 |
| 1 | 2 | 2024-07-09 18:00:00 |
| 2 | 1 | 2024-07-10 09:00:00 |
| 3 | 1 | 2024-07-10 18:00:00 |
| user_id |
|---|
| 1 |
User 1 has calls on 2024-07-09: first call with user 2 at 09:00, middle call with user 3 at 17:00, and last call with user 2 at 18:00. Since the first and last calls were both with user 2, user 1 is included in the result.
| caller_id | recipient_id | call_time |
|---|---|---|
| 1 | 2 | 2024-07-09 09:00:00 |
| 1 | 3 | 2024-07-09 18:00:00 |
| 2 | 4 | 2024-07-09 10:00:00 |
| user_id |
|---|
User 1's first call on 2024-07-09 was with user 2, but the last call was with user 3. No user has matching first and last call partners on any day, so the result is empty.
| caller_id | recipient_id | call_time |
|---|---|---|
| 1 | 2 | 2024-07-09 09:00:00 |
| 3 | 4 | 2024-07-10 10:00:00 |
| user_id |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
When a user has only one call in a day, that call is both their first and last call. Since it's with the same person (trivially), all users are included in the result.
Constraints
-
1 ≤ caller_id, recipient_id ≤ 1000 -
call_timeis a valid datetime - No duplicate calls (same caller, recipient, and time)