EasyNeetCode150ArraySortingGreedy

Meeting Rooms

Check if all meetings can attend.

Examples

Input
intervals = [[0,30],[5,10],[15,20]]
Output
false

Overlapping meetings.

Constraints

  • 1 <= intervals.length <= 10^4
  • intervals[i].length == 2

Approaches

Check all pairs.

CodeT: O(n^2) | S: O(1)

Sort and check adjacent.

CodeT: O(n log n) | S: O(1)

Same approach.

CodeT: O(n log n) | S: O(1)

Complexity Comparison

Brute Force
T: O(n^2)S: O(1)

Check all pairs.

Sort
T: O(n log n)S: O(1)

Sort and check adjacent.

Sort Optimized
T: O(n log n)S: O(1)

Same approach.

Common Mistakes

Not sorting first

Wrong comparison

Off-by-one

Try It Yourself

Copy the optimal solution and run it in our compiler.

Open in Compiler