Earliest free time slot

Write codeMedium15 minMeta and Google style

Your task

You are given an unsorted list of busy intervals [start, end], each occupying the half-open span [start, end) with nonnegative integer bounds, and a required duration d >= 1. Return the earliest nonnegative start time t such that the span [t, t + d) does not intersect any busy interval. Example: busy [[0,5],[7,9]] with d = 2 gives 5, since [5, 7) fits exactly between them.

Examples

earliest_free_slot(busy: list[list[int]], d: int) -> int
Example 1
Inputearliest_free_slot([[0, 5], [7, 9]], 2)
Output5