Drill

ProblemsTypeScript › events

Is there enough breathing room between slots

hardeventsTypeScript

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

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

Solve it in the editor →

Where you start

function minimumGap(slots: Slot[], gapMinutes: number): boolean {
  
}

Worked examples

CallResult
minimumGap([{"start":1,"end":5},{"start":10,"end":15}], 5)true
minimumGap([{"start":1,"end":5},{"start":8,"end":12}], 5)false
minimumGap([{"start":1,"end":5},{"start":15,"end":20},{"start":25,"end":30}], 5)true
minimumGap([{"start":1,"end":5}], 10)true

Hint

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

Reference solution in TypeScript
function minimumGap(slots: Slot[], gapMinutes: number): boolean {
  for (let i = 1; i < slots.length; i++) {
    if (slots[i].start - slots[i - 1].end < gapMinutes) return false;
  }
  return true;
}

The same problem in another language

More events problems in TypeScript