Single-Driver Turnaround Check

Check whether intervals are nonoverlapping with a required gap

EasyIntervalsSorting

A ride-sharing app is checking whether one driver can handle every reservation in a proposed schedule.

Each entry [start, end] in reservations represents a ride that occupies the driver from start up to, but not including, end. After each ride, the driver needs turnaround additional time units before starting another ride. Reservations may be supplied in any order, and their times cannot be changed.

Return true if the driver can complete every reservation, or false otherwise. If one ride ends at time e, the next ride may start exactly at e + turnaround.

Times are offsets from the app's scheduling reference, so negative times are allowed. An empty schedule is feasible.

Examples

Example 1

Input: reservations = [[13,16],[0,4],[7,10]], turnaround = 3
Output: true

Chronologically, the rides are [0, 4], [7, 10], and [13, 16]. Each gap is exactly the required three time units, so the schedule is feasible despite the input order.

Example 2

Input: reservations = [[0,5],[6,9]], turnaround = 2
Output: false

The first ride ends at time 5, so the driver cannot start another ride until time 7. The reservation starting at time 6 makes the schedule infeasible.

Example 3

Input: reservations = [[-4,0],[0,3]], turnaround = 0
Output: true

With no turnaround time, a ride may begin exactly when the previous ride ends. Both reservations can be completed.

Constraints

  • 0 <= reservations.length <= 2400
  • Each reservation contains exactly two integers, start and end.
  • -10^9 <= start < end <= 10^9
  • 0 <= turnaround <= 100000

The turnaround requirement applies between rides, not before the first ride or against any deadline after the last ride. The reference solutions run in O(n log n) time and use O(n) auxiliary space without modifying the input.

Hints

Show hint 1

Consider the reservations in chronological order rather than their input order.

Show hint 2

For each consecutive pair, compare the later start with the earlier end plus the turnaround time.

Follow-up questions

What an interviewer might ask once you have a working solution.

  • How would you return the original indices of a conflicting pair instead of a boolean?
  • If reservations were already sorted by start time, what time and auxiliary-space bounds could you achieve?

Practice this with an AI interviewer

Explain your approach out loud, write Python or JavaScript, run it against hidden tests (including large inputs), and get a scored debrief.

Start this problem