This question evaluates object-oriented design, interval data-structure and algorithmic thinking, and concurrent programming competence by requiring an in-memory meeting scheduler API that handles booking insertion and earliest-availability queries.
Design and implement an in-memory meeting scheduler that stores existing bookings and can answer availability queries.
You must support two operations:
addBooking(start, duration)
start
is an integer timestamp (e.g., minutes) and
duration > 0
.
earliestStart(requestStart, duration)
t >= requestStart
such that the interval
[t, t + duration)
does
not overlap
any existing booking.
Two bookings overlap if their half-open intervals intersect. For example, [10, 20) and [20, 30) do not overlap.
earliestStart
run in
O(N)
time (where N is the number of bookings) by changing how you store data?
State any assumptions you need (e.g., whether addBooking is guaranteed not to conflict, or whether conflicts should be rejected/merged).