Meeting Rooms

EasyIntervals

You get a list of meetings, each written as [start, end]. Return true if one person could attend all of them, meaning no two overlap, and false otherwise.

A meeting that starts at the very moment another ends does not overlap it: [1, 3] and [3, 5] can both be attended. The meetings are not given in any particular order.

Examples

Example 1
Input:  intervals = [[9, 11], [13, 15], [11, 12]]
Output: true

In time order: 9 to 11, 11 to 12, 13 to 15. The second starts just as the first ends.

Example 2
Input:  intervals = [[2, 5], [8, 10], [4, 7]]
Output: false

The meeting from 4 to 7 starts before the one from 2 to 5 is over.

Constraints

  • 0 ≤ intervals.length ≤ 10⁴
  • 0 ≤ start < end ≤ 10⁶

Stuck?

Hint 1

Once the meetings are sorted by start time, any clash shows up between two neighbours.

Hint 2

Sort by start, then check that each meeting starts no earlier than the one before it ends. Mind the equal case: touching is allowed.

Still stuck? Read the solution

JavaScript
Loading the editor

Run checks your code against the 2 examples. Submit checks all 10 tests, most of them hidden.

Ctrl + Enter runs, and adding Shift submits. On a Mac, use ⌘.

blur