FastPrepMy Calendar I
Problem · Array

My Calendar I

Learn this problem
MediumUber logoUberFULLTIMEONSITE INTERVIEW
See Uber hiring insights

Problem statement

You are implementing a calendar that stores booked half-open intervals [start, end).

You are given two integer arrays starts and ends of the same length. The i-th booking attempt requests the interval [starts[i], ends[i]). Accept the booking if and only if it does not overlap any already accepted interval. Adjacent bookings that only touch at an endpoint do not overlap because the end time is exclusive.

Return a boolean array where entry i is true when the i-th attempt is accepted.

Function

bookCalendar(starts: int[], ends: int[]) → boolean[]

Examples

Example 1

starts = [10,15,20]ends = [20,25,30]return = [true,false,true]

The first booking [10, 20) is accepted. The second booking [15, 25) overlaps it and is rejected. The third booking [20, 30) only touches the accepted interval at time 20, so it is accepted.

Example 2

starts = [47,33,36,25,24]ends = [50,41,45,32,33]return = [true,true,false,true,false]

[47, 50), [33, 41), and [25, 32) are disjoint and accepted. [36, 45) overlaps [33, 41), and [24, 33) overlaps [25, 32).

Constraints

  • 1 <= starts.length <= 1000.
  • ends.length == starts.length.
  • 0 <= starts[i] < ends[i] <= 10^9.

More Uber problems

drafts saved locally
public boolean[] bookCalendar(int[] starts, int[] ends) {
  // Write your code here.
}
starts[10,15,20]
ends[20,25,30]
expected[true,false,true]
checking account