101
0/304
Loading content...
A telecom analytics team wants a leaderboard of the longest calls, split by direction, for quality auditing and staffing analysis.
You are given two tables:
Contacts
Calls
Task: For each call type independently, keep only the 3 longest calls.
Ranking rules within each type:
Output requirements:
Supported submission environments:
Contacts:
| id | first_name | last_name |
|----|------------|-----------|
| 1 | Liam | Brooks |
| 2 | Ava | Clarke |
| 3 | Noah | Kim |
| 4 | Mia | Reed |
| 5 | Zoe | Patel |
Calls:
| contact_id | type | duration |
|------------|----------|----------|
| 1 | incoming | 120 |
| 1 | outgoing | 180 |
| 2 | incoming | 300 |
| 2 | outgoing | 240 |
| 3 | incoming | 150 |
| 3 | outgoing | 360 |
| 4 | incoming | 420 |
| 4 | outgoing | 200 |
| 5 | incoming | 180 |
| 5 | outgoing | 280 |[
{"first_name":"Noah","type":"outgoing","duration_formatted":"00:06:00"},
{"first_name":"Zoe","type":"outgoing","duration_formatted":"00:04:40"},
{"first_name":"Ava","type":"outgoing","duration_formatted":"00:04:00"},
{"first_name":"Mia","type":"incoming","duration_formatted":"00:07:00"},
{"first_name":"Ava","type":"incoming","duration_formatted":"00:05:00"},
{"first_name":"Zoe","type":"incoming","duration_formatted":"00:03:00"}
]Each direction keeps its own top 3 calls, then rows are ordered by type descending and duration descending.
Contacts:
| id | first_name | last_name |
|----|------------|-----------|
| 10 | Anna | Cole |
| 11 | Bella | Ives |
| 12 | Cara | Finch |
| 13 | Dana | Shah |
Calls:
| contact_id | type | duration |
|------------|----------|----------|
| 10 | outgoing | 500 |
| 11 | outgoing | 500 |
| 12 | outgoing | 500 |
| 13 | outgoing | 500 |
| 10 | incoming | 300 |
| 11 | incoming | 300 |
| 12 | incoming | 120 |
| 13 | incoming | 120 |[
{"first_name":"Dana","type":"outgoing","duration_formatted":"00:08:20"},
{"first_name":"Cara","type":"outgoing","duration_formatted":"00:08:20"},
{"first_name":"Bella","type":"outgoing","duration_formatted":"00:08:20"},
{"first_name":"Bella","type":"incoming","duration_formatted":"00:05:00"},
{"first_name":"Anna","type":"incoming","duration_formatted":"00:05:00"},
{"first_name":"Dana","type":"incoming","duration_formatted":"00:02:00"}
]For equal durations, first_name descending decides which rows remain in the top 3.
Contacts:
| id | first_name | last_name |
|----|------------|-----------|
| 21 | Ethan | Bell |
| 22 | Nia | Holt |
| 23 | Omar | Grant |
Calls:
| contact_id | type | duration |
|------------|----------|----------|
| 21 | incoming | 60 |
| 22 | incoming | 3661 |
| 23 | incoming | 59 |
| 99 | incoming | 9999 |[
{"first_name":"Nia","type":"incoming","duration_formatted":"01:01:01"},
{"first_name":"Ethan","type":"incoming","duration_formatted":"00:01:00"},
{"first_name":"Omar","type":"incoming","duration_formatted":"00:00:59"}
]Rows with unknown contacts are ignored by the join, and formatting correctly handles hour boundaries.
Constraints