public List<Interval> insertB(List<Interval> intervals,Interval newInterval){
  int i=0;
  while (i < intervals.size() && intervals.get(i).end < newInterval.start) {
    i++;
  }
  while (i < intervals.size() && intervals.get(i).start <= newInterval.end) {
    newInterval=new Interval(Math.min(intervals.get(i).start,newInterval.start),Math.max(intervals.get(i).end,newInterval.end));
    intervals.remove(i);
  }
  intervals.add(i,newInterval);
  return intervals;
}

public List < Interval > insertB ( List < Interval > intervals , Interval newInterval ) { int i = 0 ; while ( i < intervals . size ( ) && intervals . get ( i ) . end < newInterval . start ) { i ++ ; } while ( i < intervals . size ( ) && intervals . get ( i ) . start <= newInterval . end ) { newInterval = new Interval ( Math . min ( intervals . get ( i ) . start , newInterval . start ) , Math . max ( intervals . get ( i ) . end , newInterval . end ) ) ; intervals . remove ( i ) ; } intervals . add ( i , newInterval ) ; return intervals ; }
in place solution . skip the intervals not overlapping with the new one . merge all intervals overlap with the new interval . and remove them . add new interval in position .
