Created
November 25, 2017 20:35
-
-
Save vaibhav93/7c52e1521e2fe4a57d6918ad08d5dc8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int minMeetingRooms(Interval[] intervals) { | |
HashMap<Integer, Integer> map = new HashMap<>(); | |
int min=0; | |
int max=0; | |
for(int i=0;i<intervals.length;i++){ | |
if(!map.containsKey(intervals[i].start)){ | |
map.put(intervals[i].start,0); | |
} | |
if(!map.containsKey(intervals[i].end)){ | |
map.put(intervals[i].end,0); | |
} | |
min = Math.min(min, intervals[i].start); | |
max = Math.max(max, intervals[i].end); | |
map.put(intervals[i].start, map.get(intervals[i].start)+1); | |
map.put(intervals[i].end, map.get(intervals[i].end)-1); | |
} | |
int answer = 0; | |
int count=0; | |
for(int i=min;i<=max;i++){ | |
if(map.containsKey(i)){ | |
count+=map.get(i); | |
answer = Math.max(answer ,count); | |
} | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment