classSolution{publicinteraseOverlapIntervals(int[][]intervals){//same as N meetings/no. of activities//sort the intervals based on end time of each pairQueue<Pair<Integer,Integer>>q=newPriorityQueue<>((a,b)->a.getValue()-b.getValue());for(inti=0;i<intervals.length;i++){q.add(newPair(intervals[i][0],intervals[i][1]));}intpreviousEndTime=Integer.MIN_VALUE;intcount=0;while(!q.isEmpty()){Pair<Integer,Integer>p=q.remove();intstart=p.getKey();intend=p.getValue();if(start>=previousEndTime){count++;previousEndTime=end;}}returnintervals.length-count;}}
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)