Do these two bookings clash
A meeting room calendar refuses a booking that runs into another one. Times are minutes since midnight.
- An interval runs from its start up to but not including its end, so two bookings that merely touch do not clash.
- An interval whose end is not after its start is empty and clashes with nothing.
intervals_overlap(a_start: int, a_end: int, b_start: int, b_end: int) → bool
Where you start
def intervals_overlap(a_start: int, a_end: int, b_start: int, b_end: int) -> bool:
Worked examples
| Call | Result |
|---|---|
intervals_overlap(60, 120, 110, 180) | True |
intervals_overlap(60, 120, 120, 180) | False |
intervals_overlap(60, 120, 0, 30) | False |
intervals_overlap(60, 120, 70, 80) | True |
Hint
Two intervals overlap when each one starts before the other ends. Deal with the empty case first.
Reference solution in Python
def intervals_overlap(a_start: int, a_end: int, b_start: int, b_end: int) -> bool:
if a_end <= a_start or b_end <= b_start:
return False
return a_start < b_end and b_start < a_end