Drill

ProblemsC# › scheduling

How many people try to book the same slot

mediumschedulingIntervalsSortingC#

Requests come in as start/end minutes. Count how many requests are fully contained inside another request — a same-slot double booking.

ShiftConflicts(slots: list<Slot>) → int

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 int ShiftConflicts(List<Slot> slots) {
    
}

Worked examples

CallResult
ShiftConflicts(new List<Slot> { new Slot(0, 100), new Slot(10, 90), new Slot(0, 100) })3
ShiftConflicts(new List<Slot> { new Slot(0, 100), new Slot(100, 200) })0
ShiftConflicts(new List<Slot> { })0
ShiftConflicts(new List<Slot> { new Slot(5, 5), new Slot(0, 10) })1

Hint

For each request scan all the others for one strictly broader window.

Reference solution in C#
public int ShiftConflicts(List<Slot> slots) {
    int n = 0;
    for (int i = 0; i < slots.Count; i++) {
        var a = slots[i];
        bool hit = false;
        for (int j = 0; j < slots.Count; j++) {
            if (i == j) continue;
            var b = slots[j];
            if (b.Start <= a.Start && b.End >= a.End) { hit = true; break; }
        }
        if (hit) n++;
    }
    return n;
}

The same problem in another language

More scheduling problems in C#