Skip to main content

Can One Person Attend All Meetings

EasyIntervalsSorting123 tests

You get a list meetings. Each item is a pair [start, end] with start < end. The times are minutes from the start of the day. The list is not sorted.

One person wants to attend every meeting from its start to its end. A person can be in only one meeting at a time.

Return true if the person can attend all the meetings, and false if any two meetings overlap.

Note

  • A meeting that starts at the same minute another meeting ends is fine. For example, [30, 60] and [60, 90] do not overlap.
  • If the list is empty, return true.

Hint: after sorting the meetings by start time, you only need to compare each meeting with the one just before it.

Examples

Example 1

Input:
[[600,660],[540,600],[700,745]]
Output:
true

In time order the meetings are [540, 600], [600, 660] and [700, 745]. The second one starts at the minute the first one ends, which is fine. Nothing overlaps.

Example 2

Input:
[[120,300],[480,500],[250,400]]
Output:
false

[120, 300] runs until minute 300, but [250, 400] starts at minute 250. The person can not be in both meetings from 250 to 300.

Example 3

Input:
[[15,45]]
Output:
true

There is only one meeting, so nothing can overlap.

Constraints

  • 0 <= meetings.length <= 12
  • 0 <= start < end <= 1440

Run checks your code against the 3 examples. Submit checks it against all 123 tests and needs a free account. You can also try ideas in the free JavaScript or Python compiler.