import java.util.*; /**

  • Definition for an interval.
  • public class Interval {
  • int start;
    
  • int end;
    
  • Interval() { start = 0; end = 0; }
    
  • Interval(int s, int e) { start = s; end = e; }
    
  • } */ public class Solution { public ArrayList merge(ArrayList intervals) { Collections.sort(intervals,(Interval v1,Interval v2) -> v1.start - v2.start); ArrayList result = new ArrayList<>(); int index = -1; for(Interval interval :intervals){ if(index == -1 || interval.start > result.get(index).end){ result.add(interval); index ++; }else{ result.get(index).end = Math.max(result.get(index).end,interval.end); } } return result; } }