Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Markdown · 1.2 KiB · at 9472e3c

Write findFreeSlot(busy, dayStart, dayEnd, durationMin), which finds the earliest time a meeting of durationMin minutes fits in a day. All times are minutes as plain numbers.

  • busy is a list of { start, end } intervals. Each interval is half-open, [start, end): it occupies minute start up to but not including end, so a meeting may start exactly when a busy interval ends and may end exactly when one starts.
  • The intervals are in no particular order, may overlap or contain each other, and may start before dayStart or end after dayEnd. Intervals entirely outside the day have no effect.
  • A meeting starting at minute s occupies [s, s + durationMin). It fits if s >= dayStart, s + durationMin <= dayEnd (ending exactly at dayEnd is fine), and it overlaps no busy interval.

Return the smallest s at which the meeting fits. The result is absent when there is no such s.

Validation (checked before searching): fail with { kind: "invalid_input" } when any of dayStart, dayEnd, durationMin, or any interval's start or end is not an integer, when durationMin <= 0, when dayEnd <= dayStart, or when any interval has end <= start.

Do not modify busy or its intervals.