Katkat

Design a meeting scheduler API

LinkedInSoftware Engineer · Onsite

Last updated

This problem tests your ability to design a thread-safe scheduling system using interval management techniques and efficient data structures for range querying.

Meeting Scheduler API

Design an in-memory MeetingScheduler class that manages meeting bookings for a single room and provides methods to add meetings and find the earliest available time slot.

You are required to implement the following interface:

class MeetingScheduler:
    def __init__(self):
        """Initializes the scheduler."""

    def book(self, start: int, end: int) -> bool:
        """Books a meeting from start to end (exclusive). Returns True if successful, False if there is a conflict."""

    def earliest_available(self, duration: int, search_start: int, search_end: int) -> int:
        """Finds the start time of the first available slot of 'duration' length within [search_start, search_end). Returns -1 if no such slot exists."""

Constraints

  • Time inputs are integers representing minutes from the start of the day.
  • The system must handle concurrent calls to book safely.
  • Efficiency is critical; consider the complexity of both finding gaps and inserting intervals.

Example

scheduler = MeetingScheduler()
scheduler.book(10, 20)      # Returns True
scheduler.book(15, 25)      # Returns False (Overlap)
scheduler.earliest_available(10, 0, 50) # Returns 20 (gap between 20 and 50)

Edge Cases

  • Zero-length meetings or zero-duration search requests.
  • Search range starts after the last booked meeting.
  • Fully overlapping, partially overlapping, and contiguous meeting blocks.

Hints

Hint 1

Consider storing bookings in a sorted data structure based on start times to simplify conflict detection.

Hint 2

For the earliest_available method, you can iterate through the gaps between sorted, non-overlapping intervals to find a slot that fits the required duration.

Hint 3

Use a reentrant lock or a reader-writer lock to ensure that multiple threads can query for availability simultaneously while exclusive access is maintained during booking updates.

Follow-up questions

  • How would your design change if the system needed to handle millions of rooms rather than just one?
  • If the booking data must be persisted, what database schema and indexing strategy would you use to support the `earliest_available` query?
  • How would you handle a 'cancel_meeting' requirement while maintaining the efficiency of your current implementation?