Complete the code to create an interval object with start and end values.
Interval interval = new Interval([1], 10);
The interval start value should be a number, so 5 is correct.
Complete the code to check if two intervals overlap.
boolean overlap = interval1.end [1] interval2.start;Two intervals overlap if the end of the first is greater than the start of the second.
Fix the error in the code to merge two overlapping intervals.
int mergedEnd = Math.[1](interval1.end, interval2.end);When merging intervals, the merged end is the maximum of both ends.
Fill both blanks to create a list of merged intervals from a list of intervals.
for (Interval current : intervals) { if (merged.isEmpty() || merged.get(merged.size() - 1).end [1] current.start) { merged.[2](current); } else { merged.get(merged.size() - 1).end = Math.max(merged.get(merged.size() - 1).end, current.end); } }
We add the current interval if no overlap (end <= start). Otherwise, we merge.
Fill all three blanks to filter intervals that start after a given time and sort them by start time.
List<Interval> filtered = intervals.stream()
.filter(i -> i.start [1] [2])
.sorted(Comparator.comparingInt(i -> i.[3]))
.collect(Collectors.toList());Filter intervals starting after 5, then sort by start time.
