CodeArchon

easyIntervalsLinkedIn

Boardroom Conflict Check

A dispatcher checks whether one presenter can take all meetings back-to-back with no clash.

Given meeting intervals, return true iff a single person can attend all meetings (no two overlap).

Choose approach

1/2
Narrationstep 1 of 2

Sorted by start.

1def canAttendMeetings(intervals):
2 intervals.sort(key=lambda x: x[0])
3 for i in range(1, len(intervals)):
4 if intervals[i][0] < intervals[i-1][1]: return False
5 return True
Variables

How to think about it

  1. Any overlap after sort fails.
  2. O(n) scan post-sort.

Edge cases to catch in interview

  • Empty -> true.
  • Touching endpoints (end == next.start) OK.

Examples

Example 1true
{"intervals":[[7,10],[2,4]]}

Try your own input

SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed