Problems › Python › scheduling
Do these two shifts overlap
Time-and-a-half rules ban one person covering two shifts at once. Minutes are counted from midnight; decide whether two shift windows share any time at all.
- A shift ends exactly when the next begins: that is still a handover, not an overlap.
- Shifts never wrap past midnight here.
shifts_overlap(first_start: int, first_end: int, second_start: int, second_end: int) → bool
Where you start
def shifts_overlap(first_start: int, first_end: int, second_start: int, second_end: int) -> bool:
Worked examples
| Call | Result |
|---|---|
shifts_overlap(480, 900, 840, 1020) | True |
shifts_overlap(480, 900, 900, 1020) | False |
shifts_overlap(480, 840, 900, 1020) | False |
shifts_overlap(480, 900, 500, 600) | True |
Hint
Two windows overlap exactly when each starts before the other ends.
Reference solution in Python
def shifts_overlap(first_start: int, first_end: int, second_start: int, second_end: int) -> bool:
return first_start < second_end and second_start < first_end