Drill

ProblemsPython › scheduling

Do these two shifts overlap

easyschedulingPython

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.

shifts_overlap(first_start: int, first_end: int, second_start: int, second_end: int) → bool

Solve it in the editor →

Where you start

def shifts_overlap(first_start: int, first_end: int, second_start: int, second_end: int) -> bool:
    

Worked examples

CallResult
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

The same problem in another language

More scheduling problems in Python