252. Meeting Rooms

Description

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

Constraints

  • 0 <= intervals.length <= 104

  • intervals.length == 2

  • 0 <= starti < endi <= 106

Approach

  • GeeksforGeeks

  • ProgramCreek

  • YouTube

Examples

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

Output: false

Solutions

/**
 * Time complexity : O(N*N)
 * Space complexity : O(1)
 */
 
 class Solution {

  public boolean canAttendMeetings(int[][] intervals) {
    for (int i = 0; i < intervals.length; i++) {
      for (int j = i + 1; j < intervals.length; j++) {
        if (overlap(intervals[i], intervals[j]))
          return false;
      }
    }
    return true;
  }

  public static boolean overlap(int[] i1, int[] i2) {
    return ((i1[0] >= i2[0] && i1[0] < i2[1]) || 
              (i2[0] >= i1[0] && i2[0] < i1[1]));
  }
}

Follow up

Last updated

Was this helpful?