Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Detect Booking Time Overlaps
00:00
5 left

Detect Booking Time Overlaps

EasyPython

Problem

Turo needs to determine whether a specific vehicle has conflicting bookings. Given booking records and a vehicle ID, return True if any two bookings for that vehicle overlap, otherwise return False.

Treat each booking interval as half-open: [start, end). Therefore, a booking ending at time 10 does not overlap a booking starting at time 10.

Formal Specification

Implement detect_booking_overlap(bookings, vehicle_id). bookings is a list of dictionaries, each containing:

  • vehicle_id: a string
  • start: an integer start timestamp
  • end: an integer end timestamp

Return a boolean. Only bookings whose vehicle_id matches the requested vehicle should be considered. The input is not necessarily sorted.

Constraints

  • 0 <= len(bookings) <= 10^5
  • Each booking contains vehicle_id, start, and end
  • start < end for every booking
  • 0 <= start < end <= 10^9
  • The requested vehicle_id is a non-empty string

Function Signature

def detect_booking_overlap(bookings, vehicle_id):
Interviewer

Your question is Detect Booking Time Overlaps. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.