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.
busyis a list of{ start, end }intervals. Each interval is half-open,[start, end): it occupies minutestartup to but not includingend, 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
dayStartor end afterdayEnd. Intervals entirely outside the day have no effect. - A meeting starting at minute
soccupies[s, s + durationMin). It fits ifs >= dayStart,s + durationMin <= dayEnd(ending exactly atdayEndis 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.