time : O( max timeEnd), but get ask result is O(1)
space: O(50050)
publicclassSolution { /** * @param intervals: the intervals * @param rooms: the sum of rooms * @param ask: the ask * @return: true or false of each meeting */publicboolean[] meetingRoomIII(int[][] intervals,int rooms,int[][] ask) {boolean[] res =newboolean[ask.length]; int[] sum =newint[50050];int[] times =newint[50050];int timeEnd =0;for (int[] interval : intervals) {int start = interval[0];int end = interval[1]; times[start]++; times[end]--; timeEnd =Math.max(timeEnd, end); // update max time end }// update max time endfor (int[] a : ask) { timeEnd =Math.max(timeEnd, a[1]); }// mark in sum[i] this time index is a empty roomint temp =0;for (int i =1; i < timeEnd; i++) { temp += times[i]; sum[i] = (temp < rooms) ?0:1; }System.out.println(Arrays.toString(Arrays.copyOf(sum,11)));for (int i =1; i < timeEnd; i++) { sum[i] += sum[i-1]; }System.out.println(Arrays.toString(Arrays.copyOf(sum,11)));for (int i =0; i <ask.length; i++) {int start = ask[i][0];int end = ask[i][1]; res[i] = (sum[start -1] == sum[end -1]); }return res; }}