> For the complete documentation index, see [llms.txt](https://timmybeeflin.gitbook.io/cracking-leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timmybeeflin.gitbook.io/cracking-leetcode/array_problem/lintcode-1897-meeting-room-iii.md).

# lintcode - 1897 · Meeting Room III

<https://www.lintcode.com/problem/1897/?utm_source=sc-libao-zyq>

## line sweep + presum

```
[[1,2],[4,5],[8,10]]
1
[[2,3],[3,4]]


sum[i]: [0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0] (mark 1 or 0
sum[i]: [0, 1, 1, 1, 2, 2, 2, 2, 3, 4, 0] (do presum
```

time : O( max timeEnd), but get ask result is O(1)

space: O(50050)

```java
public class Solution {
    /**
     * @param intervals: the intervals
     * @param rooms: the sum of rooms
     * @param ask: the ask
     * @return: true or false of each meeting
     */
    public boolean[] meetingRoomIII(int[][] intervals, int rooms, int[][] ask) {
        boolean[] res = new boolean[ask.length]; 

        int[] sum = new int[50050];
        int[] times = new int[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 end
        for (int[] a : ask) {
            timeEnd = Math.max(timeEnd, a[1]);
        }

        // mark in sum[i] this time index is a empty room
        int 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;
    }
    
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://timmybeeflin.gitbook.io/cracking-leetcode/array_problem/lintcode-1897-meeting-room-iii.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
