educative.io

Educative

Will this be also an acceptable solution?

  public static int findMinimumMeetingRooms(List<Meeting> meetings) {
    
    if(meetings == null || meetings.size() == 0) {
      return -1;
    }

    Collections.sort(meetings, (l, r) -> l.start - r.start);

    int rooms = 1;
    int count = 1;
    int i = 0;
    int j = 1;

    while(i < j && i < meetings.size() - 1) {
      if(j + 1 < meetings.size() && meetings.get(i).end > meetings.get(j).start) {        
        count++;
        j++;
        rooms = Math.max(rooms, count);
      }
      else if(meetings.get(i).end <= meetings.get(j).start){
        count = Math.max(1, count - 1);
        i++;
        if(i == j && j + 1 < meetings.size()) {
          j++;
        }
      }
      else {
        i++;
      }
    }

    return Math.max(count, rooms);
  }



----
Type your question above this line.

Course: https://www.educative.io/collection/5668639101419520/5671464854355968
Lesson: https://www.educative.io/collection/page/5668639101419520/5671464854355968/5710239819104256