# C++ solution using a map. total 11 lines

• class Solution {
public:
int minMeetingRooms(vector<Interval>& intervals) {
map<int, int> mp; // key: time; val: +1 if start, -1 if end

``````    for(int i=0; i< intervals.size(); i++) {
mp[intervals[i].start] ++;
mp[intervals[i].end] --;
}

int cnt = 0, maxCnt = 0;
for(auto it = mp.begin(); it != mp.end(); it++) {
cnt += it->second;
maxCnt = max( cnt, maxCnt);
}

return maxCnt;
}
``````

};

• holy high holy high !!!!!!!!!!

• Nice solution!!

Here is my Python implementation:

``````def minMeetingRooms(intervals):

mp = collections.defaultdict(int)
for item in intervals:
mp[item.start] += 1
mp[item.end] -= 1

ret = cnt = 0
for i in sorted(mp.keys()):
cnt += mp[i]
ret = max(ret, cnt)
return ret``````

• so f**king terrific!!!!!!

• That's truly a sign of cleverness!

• What is the time complexity? Why is it so slow in the online judge?.

• This solution is so terrific! 牛逼！

• you are god!

• @eeriee The complexity seems to be `O(2nlog2n)+O(2nlog2n)=O(4nlogn+4nlog2)=O(nlogn)`. I think the large constant factor and lower order term contribute to its slowness.

• Brilliant !!!! This looks like the valid parentheses to me!

• Fucking impressive.

• Thanks, very resourceful

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