Do two bookings clash
A calendar checker takes two half-open intervals and reports whether they overlap.
- Each interval is [start, end) — the end moment is excluded.
- An interval whose end is not after its start is empty and clashes with nothing.
bookings_overlap(first_start: int, first_end: int, second_start: int, second_end: int) → bool
Where you start
def bookings_overlap(first_start: int, first_end: int, second_start: int, second_end: int) -> bool:
Worked examples
| Call | Result |
|---|---|
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