Menu
CoddyTech

Meeting Rooms

You get a list of meetings as two arrays: meeting i runs from starts[i] to ends[i]. One person wants to attend all of them, so no two meetings may overlap. A meeting may start at the exact moment another one ends. Return true if the person can attend every meeting, and false otherwise.

Function

canAttendMeetings(starts: integer-array, ends: integer-array) → boolean
startsinteger-array
the start time of each meeting
endsinteger-array
the end time of each meeting, at the same index as its start
Returnsboolean
true if no two meetings overlap, false otherwise

Constraints

  • 1 ≤ starts.length == ends.length ≤ 5000
  • 0 ≤ starts[i] < ends[i] ≤ 106
  • The meetings are not sorted. Two meetings may be identical.

Examples

Input
starts = [9, 13, 10]ends = [10, 15, 12]
Output
true
Explanation
In time order the meetings run from 9 to 10, 10 to 12 and 13 to 15. The second one starts the moment the first one ends, which is allowed, so the answer is true.

lock icon+15 hidden tests on Submit

challenge icon

Follow-up

If meetings are booked one at a time, how would you check each new booking against the schedule in O(log n), without sorting everything again?

Reset code
def canAttendMeetings(starts, ends):
    # Write code here
Test cases

Case 1

Case 2

Input

starts = [9, 13, 10]
ends = [10, 15, 12]

Expected

true