class MyCalendarTwo {
List<int[]> times;
List<int[]> overlaps;
public MyCalendarTwo() {
times = new ArrayList<>();
overlaps = new ArrayList<>();
}
public boolean book(int start, int end) {
for (int[] overlap : overlaps) {
if (Math.max(start, overlap[0]) < Math.min(end, overlap[1])) {
return false;
}
}
for (int[] time : times) {
if (Math.max(start, time[0]) < Math.min(end, time[1])) {
overlaps.add(new int[] {Math.max(start, time[0]), Math.min(end, time[1])});
}
}
times.add(new int[] {start, end});
return true;
}
}
/**
* Your MyCalendarTwo object will be instantiated and called as such:
* MyCalendarTwo obj = new MyCalendarTwo();
* boolean param_1 = obj.book(start,end);
*/