iq.lab
Python starts when a code cell comes near or you run one
easySortingSort by start and sweep target 15 min

Attend every meeting

Each meeting is a pair [start, end]: it begins at minute start and is over at minute end. The list intervals holds one person's meetings, in no particular order. Can that person sit through every meeting from start to end? Return True if no two meetings overlap, and False if any two do.

Two meetings overlap when each one starts before the other ends, so they share some time. A meeting may start at the exact minute another ends: [1, 3] and [3, 5] do not overlap.

Example 1
Inputintervals = [[9, 10], [1, 4], [5, 8]]OutputTrue

In time order they run 1 to 4, 5 to 8, 9 to 10. Each one ends before the next begins.

Example 2
Inputintervals = [[6, 9], [1, 3], [2, 5]]OutputFalse

[2, 5] starts at minute 2, before [1, 3] ends at minute 3.

Example 3
Inputintervals = [[3, 5], [1, 3]]OutputTrue

One ends at minute 3 and the other starts at minute 3. Touching is not overlapping.

Constraints
  • 0 ≤ len(intervals) ≤ 105

  • 0 ≤ start < end ≤ 106

Plan it first

Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.