Drill

ProblemsPython › scheduling

How many people try to book the same slot

mediumschedulingPython

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

shift_conflicts(slots: list<Slot>) → int

Solve it in the editor →

Where you start

def shift_conflicts(slots: list[Slot]) -> int:
    

Worked examples

CallResult
shift_conflicts([Slot(start=0, end=100), Slot(start=10, end=90), Slot(start=0, end=100)])3
shift_conflicts([Slot(start=0, end=100), Slot(start=100, end=200)])0
shift_conflicts([])0
shift_conflicts([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 Python
def shift_conflicts(slots: list[Slot]) -> int:
    n = 0
    for i, a in enumerate(slots):
        if any(j != i and b.start <= a.start and b.end >= a.end for j, b in enumerate(slots)):
            n += 1
    return n

The same problem in another language

More scheduling problems in Python