Drill

ProblemsPython › events

Is there enough breathing room between slots

hardeventsPython

A scheduler requires a minimum pause between consecutive bookings. Verify every gap meets the requirement.

minimum_gap(slots: list<Slot>, gap_minutes: int) → bool

Solve it in the editor →

Where you start

def minimum_gap(slots: list[Slot], gap_minutes: int) -> bool:
    

Worked examples

CallResult
minimum_gap([Slot(start=1, end=5), Slot(start=10, end=15)], 5)True
minimum_gap([Slot(start=1, end=5), Slot(start=8, end=12)], 5)False
minimum_gap([Slot(start=1, end=5), Slot(start=15, end=20), Slot(start=25, end=30)], 5)True
minimum_gap([Slot(start=1, end=5)], 10)True

Hint

Walk the list once, checking the gap between each pair of neighbours.

Reference solution in Python
def minimum_gap(slots: list[Slot], gap_minutes: int) -> bool:
    for i in range(1, len(slots)):
        if slots[i].start - slots[i - 1].end < gap_minutes:
            return False
    return True

The same problem in another language

More events problems in Python