Loading problem...
A workforce analytics team needs a collision counter for employee shifts on a single day.
Table: EmployeeShifts
Rules:
For each employee, count overlapping ordered shift pairs (A, B) such that:
Interpretation notes:
Output requirements:
Supported submission environments:
EmployeeShifts:
| employee_id | start_time | end_time |
|-------------|------------|----------|
| 1 | 08:00:00 | 12:00:00 |
| 1 | 11:00:00 | 15:00:00 |
| 1 | 14:00:00 | 18:00:00 |
| 2 | 09:00:00 | 17:00:00 |
| 2 | 16:00:00 | 20:00:00 |
| 3 | 10:00:00 | 12:00:00 |
| 3 | 13:00:00 | 15:00:00 |
| 3 | 16:00:00 | 18:00:00 |
| 4 | 08:00:00 | 10:00:00 |
| 4 | 09:00:00 | 11:00:00 |[
{"employee_id":1,"overlapping_shifts":2},
{"employee_id":2,"overlapping_shifts":1},
{"employee_id":4,"overlapping_shifts":1}
]Employee 1 has two overlapping ordered pairs, employee 2 has one, employee 3 has zero, and employee 4 has one.
EmployeeShifts:
| employee_id | start_time | end_time |
|-------------|------------|----------|
| 10 | 08:00:00 | 10:00:00 |
| 10 | 10:00:00 | 12:00:00 |
| 10 | 11:00:00 | 13:00:00 |
| 11 | 09:00:00 | 12:00:00 |
| 11 | 09:30:00 | 10:30:00 |
| 11 | 10:30:00 | 11:30:00 |[
{"employee_id":10,"overlapping_shifts":1},
{"employee_id":11,"overlapping_shifts":2}
]Boundary-touching shifts (end == next start) are not overlaps, but true strict-overlap pairs are counted.
EmployeeShifts:
| employee_id | start_time | end_time |
|-------------|------------|----------|
| 22 | 05:00:00 | 23:00:00 |
| 22 | 06:00:00 | 22:00:00 |
| 22 | 07:00:00 | 21:00:00 |
| 22 | 08:00:00 | 20:00:00 |
| 21 | 06:00:00 | 07:00:00 |
| 21 | 07:00:00 | 08:00:00 |[
{"employee_id":22,"overlapping_shifts":6}
]Employee 22 has 4 fully nested shifts, so every ordered pair overlaps. Employee 21 has touching shifts and is excluded.
Constraints