Optimizing Interval Erasure With Efficient Sorting And Prioritization
Erase Overlap Intervals: Sort intervals by end time, remove overlapping ones. Count non-overlapping intervals and return length - count.
Problem class Solution { public int eraseOverlapIntervals(int[][] intervals) { //same as N meetings/no. of activities //sort the intervals based on end time of each pair Queue<Pair<Integer,Integer>> q = new PriorityQueue<>((a,b)->a.getValue()-b.getValue()); for(int i = 0;i<intervals.length;i++){ q.add(new Pair(intervals[i][0], intervals[i][1])); } int previousEndTime = Integer.MIN_VALUE; int count = 0; while(!q.isEmpty()){ Pair<Integer,Integer> p = q.remove(); int start = p.getKey();...