# Super Easy Java Solution Beats 98.8%

• ``````public class Solution {
public int minMeetingRooms(Interval[] intervals) {
int[] starts = new int[intervals.length];
int[] ends = new int[intervals.length];
for(int i=0; i<intervals.length; i++) {
starts[i] = intervals[i].start;
ends[i] = intervals[i].end;
}
Arrays.sort(starts);
Arrays.sort(ends);
int rooms = 0;
int endsItr = 0;
for(int i=0; i<starts.length; i++) {
if(starts[i]<ends[endsItr])
rooms++;
else
endsItr++;
}
return rooms;
}
}``````

• Super Nice Solution. I was asked this exact question on an interview.

• can you explain why this method work?

• Very nice, that lazy releasing of rooms. Here are two Python versions, each got 64 ms on first submission, beating 99.42%.

``````def minMeetingRooms(self, intervals):
ends = sorted(i.end for i in intervals)
rooms = ended = 0
for start in sorted(i.start for i in intervals):
if start < ends[ended]:
rooms += 1
else:
ended += 1
return rooms

def minMeetingRooms(self, intervals):
ends = sorted(i.end for i in intervals)[::-1]
rooms = 0
for start in sorted(i.start for i in intervals):
if start < ends[-1]:
rooms += 1
else:
ends.pop()
return rooms
``````

• awesome solution!

• @StefanPochmann
I like that name: "lazy releasing"! It tell us vividly what happen.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.