Drill

ProblemsTypeScript › scheduling

How many people try to book the same slot

mediumschedulingTypeScript

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

Solve it in the editor →

Where you start

function shiftConflicts(slots: Slot[]): number {
  
}

Worked examples

CallResult
shiftConflicts([{"start":0,"end":100},{"start":10,"end":90},{"start":0,"end":100}])3
shiftConflicts([{"start":0,"end":100},{"start":100,"end":200}])0
shiftConflicts([])0
shiftConflicts([{"start":5,"end":5},{"start":0,"end":10}])1

Hint

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

Reference solution in TypeScript
function shiftConflicts(slots: Slot[]): number {
  let n = 0;
  for (let i = 0; i < slots.length; i++) {
    for (let j = 0; j < slots.length; j++) {
      if (i !== j && slots[j].start <= slots[i].start && slots[j].end >= slots[i].end) {
        n++;
        break;
      }
    }
  }
  return n;
}

The same problem in another language

More scheduling problems in TypeScript