Drill

ProblemsC# › events

Is there enough breathing room between slots

hardeventsIntervalsSortingC#

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

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

C# 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

public bool MinimumGap(List<Slot> slots, int gapMinutes) {
    
}

Worked examples

CallResult
MinimumGap(new List<Slot> { new Slot(1, 5), new Slot(10, 15) }, 5)true
MinimumGap(new List<Slot> { new Slot(1, 5), new Slot(8, 12) }, 5)false
MinimumGap(new List<Slot> { new Slot(1, 5), new Slot(15, 20), new Slot(25, 30) }, 5)true
MinimumGap(new List<Slot> { new Slot(1, 5) }, 10)true

Hint

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

Reference solution in C#
public bool MinimumGap(List<Slot> slots, int gapMinutes) {
    for (int i = 1; i < slots.Count; i++) {
        if (slots[i].Start - slots[i - 1].End < gapMinutes) return false;
    }
    return true;
}

The same problem in another language

More events problems in C#