java.lang.Object
g2701_2800.s2747_count_zero_request_servers.Solution

public class Solution extends Object
2747 - Count Zero Request Servers.<p>Medium</p> <p>You are given an integer <code>n</code> denoting the total number of servers and a <strong>2D</strong> <strong>0-indexed</strong> integer array <code>logs</code>, where <code>logs[i] = [server_id, time]</code> denotes that the server with id <code>server_id</code> received a request at time <code>time</code>.</p> <p>You are also given an integer <code>x</code> and a <strong>0-indexed</strong> integer array <code>queries</code>.</p> <p>Return <em>a <strong>0-indexed</strong> integer array</em> <code>arr</code> <em>of length</em> <code>queries.length</code> <em>where</em> <code>arr[i]</code> <em>represents the number of servers that <strong>did not receive</strong> any requests during the time interval</em> <code>[queries[i] - x, queries[i]]</code>.</p> <p>Note that the time intervals are inclusive.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Explanation:</strong></p> <p>For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10].</p> <p>Hence, only server 3 gets zero requests.</p> <p>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.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]</p> <p><strong>Output:</strong> [0,1]</p> <p><strong>Explanation:</strong></p> <p>For queries[0]: All servers get at least one request in the duration of [1, 3].</p> <p>For queries[1]: Only server with id 3 gets no request in the duration [2,4].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>1 <= logs.length <= 10<sup>5</sup></code></li> <li><code>1 <= queries.length <= 10<sup>5</sup></code></li> <li><code>logs[i].length == 2</code></li> <li><code>1 <= logs[i][0] <= n</code></li> <li><code>1 <= logs[i][1] <= 10<sup>6</sup></code></li> <li><code>1 <= x <= 10<sup>5</sup></code></li> <li><code>x < queries[i] <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countServers

      public int[] countServers(int n, int[][] logs, int x, int[] qs)