#2747

Count Zero Request Servers

expert · 1070 · lc medium +32 · verified · 35.7% accepted · 402 likes · top 13%

Description

You have n servers and a log array where logs[i] = [server_id, time]. Given a window size x and a queries array, for each query q count how many servers received zero requests in the inclusive time window [q - x, q]. Return the array of counts.

Example 1:

Input: n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
Output: [1,2]
Explanation:
For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.
For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.

Example 2:

Input: n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
Output: [0,1]
Explanation:
For queries[0]: All servers get at least one request in the duration of [1, 3].
For queries[1]: Only server with id 3 gets no request in the duration [2,4].

Code

1
2
3