How many people try to book the same slot
Requests come in as start/end minutes. Count how many requests are fully contained inside another request — a same-slot double booking.
- A request is contained when another request starts no later and ends no earlier.
- Two identical requests each contain the other; count every one that is contained, so both are flagged.
- A request never contains itself.
shiftConflicts(slots: list<Slot>) → int
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.
Where you start
func shiftConflicts(slots []Slot) int {
}
Worked examples
| Call | Result |
|---|---|
shiftConflicts([]Slot{Slot{Start: 0, End: 100}, Slot{Start: 10, End: 90}, Slot{Start: 0, End: 100}}) | 3 |
shiftConflicts([]Slot{Slot{Start: 0, End: 100}, Slot{Start: 100, End: 200}}) | 0 |
shiftConflicts([]Slot{}) | 0 |
shiftConflicts([]Slot{Slot{Start: 5, End: 5}, Slot{Start: 0, End: 10}}) | 1 |
Hint
For each request scan all the others for one strictly broader window.
Reference solution in Go
func shiftConflicts(slots []Slot) int {
n := 0
for i, a := range slots {
hit := false
for j, b := range slots {
if i == j {
continue
}
if b.Start <= a.Start && b.End >= a.End {
hit = true
break
}
}
if hit {
n++
}
}
return n
}