Drill

ProblemsGo › events

Is there enough breathing room between slots

hardeventsIntervalsSortingGo

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

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

Go 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

func minimumGap(slots []Slot, gapMinutes int) bool {
	
}

Worked examples

CallResult
minimumGap([]Slot{Slot{Start: 1, End: 5}, Slot{Start: 10, End: 15}}, 5)true
minimumGap([]Slot{Slot{Start: 1, End: 5}, Slot{Start: 8, End: 12}}, 5)false
minimumGap([]Slot{Slot{Start: 1, End: 5}, Slot{Start: 15, End: 20}, Slot{Start: 25, End: 30}}, 5)true
minimumGap([]Slot{Slot{Start: 1, End: 5}}, 10)true

Hint

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

Reference solution in Go
func minimumGap(slots []Slot, gapMinutes int) bool {
	for i := 1; i < len(slots); i++ {
		if slots[i].Start-slots[i-1].End < gapMinutes {
			return false
		}
	}
	return true
}

The same problem in another language

More events problems in Go