Find the fewest slot removals to eliminate overlaps
A recording studio has one booth and a list of requested booking slots. Some requests overlap, so a few have to be turned down. The studio wants to keep as many bookings as possible, which means cancelling as few as possible.
Implement minSlotRemovals(slots). It returns the smallest number of slots you must remove so that no two of the remaining slots overlap.
minSlotRemovals(slots) // => number
slots is an array of [start, end] pairs of integers with start < end. Values can be negative.[start, end). Two slots overlap only when one starts strictly before the other ends, so [9, 10] and [10, 11] can both be kept.0 for an empty array or when nothing overlaps.slots or any of its pairs.minSlotRemovals([[9, 12], [10, 11], [11, 13]]);
// => 1 remove [9, 12]; [10, 11] and [11, 13] only touch
minSlotRemovals([[8, 18], [9, 10], [10, 11], [13, 15]]);
// => 1 one long session blocks three short ones
minSlotRemovals([[14, 16], [14, 16], [14, 16]]);
// => 2 identical requests: keep one
minSlotRemovals([[1, 2], [2, 3], [5, 8]]);
// => 0
minSlotRemovals([]);
// => 0