Drill

ProblemsPython › events

Do two bookings clash

easyeventsPython

A calendar checker takes two half-open intervals and reports whether they overlap.

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

Solve it in the editor →

Where you start

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

Worked examples

CallResult
bookings_overlap(10, 20, 15, 25)True
bookings_overlap(10, 20, 20, 30)False
bookings_overlap(10, 20, 25, 30)False
bookings_overlap(10, 30, 15, 20)True

Hint

Two non-empty intervals overlap when each starts before the other ends.

Reference solution in Python
def bookings_overlap(first_start: int, first_end: int, second_start: int, second_end: int) -> bool:
    if first_end <= first_start or second_end <= second_start:
        return False
    return first_start < second_end and second_start < first_end

The same problem in another language

More events problems in Python