Drill

ProblemsJava › events

Is there enough breathing room between slots

hardeventsIntervalsSortingJava

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

minimumGap(slots: list<Slot>, gapMinutes: int) → bool

Java needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

boolean minimumGap(List<Slot> slots, int gapMinutes) {
    
}

Worked examples

CallResult
minimumGap(Main.<Slot>ls(new Slot(1, 5), new Slot(10, 15)), 5)true
minimumGap(Main.<Slot>ls(new Slot(1, 5), new Slot(8, 12)), 5)false
minimumGap(Main.<Slot>ls(new Slot(1, 5), new Slot(15, 20), new Slot(25, 30)), 5)true
minimumGap(Main.<Slot>ls(new Slot(1, 5)), 10)true

Hint

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

Reference solution in Java
boolean minimumGap(List<Slot> slots, int gapMinutes) {
    for (int i = 1; i < slots.size(); i++) {
        if (slots.get(i).start - slots.get(i - 1).end < gapMinutes) return false;
    }
    return true;
}

The same problem in another language

More events problems in Java