mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
update
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
"titleSlug": "find-servers-that-handled-most-number-of-requests",
|
||||
"content": "<p>You have <code>k</code> servers numbered from <code>0</code> to <code>k-1</code> that are being used to handle multiple requests simultaneously. Each server has infinite computational capacity but <strong>cannot handle more than one request at a time</strong>. The requests are assigned to servers according to a specific algorithm:</p>\n\n<ul>\n\t<li>The <code>i<sup>th</sup></code> (0-indexed) request arrives.</li>\n\t<li>If all servers are busy, the request is dropped (not handled at all).</li>\n\t<li>If the <code>(i % k)<sup>th</sup></code> server is available, assign the request to that server.</li>\n\t<li>Otherwise, assign the request to the next available server (wrapping around the list of servers and starting from 0 if necessary). For example, if the <code>i<sup>th</sup></code> server is busy, try to assign the request to the <code>(i+1)<sup>th</sup></code> server, then the <code>(i+2)<sup>th</sup></code> server, and so on.</li>\n</ul>\n\n<p>You are given a <strong>strictly increasing</strong> array <code>arrival</code> of positive integers, where <code>arrival[i]</code> represents the arrival time of the <code>i<sup>th</sup></code> request, and another array <code>load</code>, where <code>load[i]</code> represents the load of the <code>i<sup>th</sup></code> request (the time it takes to complete). Your goal is to find the <strong>busiest server(s)</strong>. A server is considered <strong>busiest</strong> if it handled the most number of requests successfully among all the servers.</p>\n\n<p>Return <em>a list containing the IDs (0-indexed) of the <strong>busiest server(s)</strong></em>. You may return the IDs in any order.</p>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/09/08/load-1.png\" style=\"width: 389px; height: 221px;\" />\n<pre>\n<strong>Input:</strong> k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \n<strong>Output:</strong> [1] \n<strong>Explanation:</strong> \nAll of the servers start out available.\nThe first 3 requests are handled by the first 3 servers in order.\nRequest 3 comes in. Server 0 is busy, so it's assigned to the next available server, which is 1.\nRequest 4 comes in. It cannot be handled since all servers are busy, so it is dropped.\nServers 0 and 2 handled one request each, while server 1 handled two requests. Hence server 1 is the busiest server.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\n<strong>Output:</strong> [0]\n<strong>Explanation:</strong> \nThe first 3 requests are handled by first 3 servers.\nRequest 3 comes in. It is handled by server 0 since the server is available.\nServer 0 handled two requests, while servers 1 and 2 handled one request each. Hence server 0 is the busiest server.\n</pre>\n\n<p><strong>Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> k = 3, arrival = [1,2,3], load = [10,12,11]\n<strong>Output:</strong> [0,1,2]\n<strong>Explanation:</strong> Each server handles a single request, so they are all considered the busiest.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= arrival.length, load.length <= 10<sup>5</sup></code></li>\n\t<li><code>arrival.length == load.length</code></li>\n\t<li><code>1 <= arrival[i], load[i] <= 10<sup>9</sup></code></li>\n\t<li><code>arrival</code> is <strong>strictly increasing</strong>.</li>\n</ul>\n",
|
||||
"translatedTitle": "找到处理最多请求的服务器",
|
||||
"translatedContent": "<p>你有 <code>k</code> 个服务器,编号为 <code>0</code> 到 <code>k-1</code> ,它们可以同时处理多个请求组。每个服务器有无穷的计算能力但是 <strong>不能同时处理超过一个请求</strong> 。请求分配到服务器的规则如下:</p>\n\n<ul>\n\t<li>第 <code>i</code> (序号从 0 开始)个请求到达。</li>\n\t<li>如果所有服务器都已被占据,那么该请求被舍弃(完全不处理)。</li>\n\t<li>如果第 <code>(i % k)</code> 个服务器空闲,那么对应服务器会处理该请求。</li>\n\t<li>否则,将请求安排给下一个空闲的服务器(服务器构成一个环,必要的话可能从第 0 个服务器开始继续找下一个空闲的服务器)。比方说,如果第 <code>i</code> 个服务器在忙,那么会查看第 <code>(i+1)</code> 个服务器,第 <code>(i+2)</code> 个服务器等等。</li>\n</ul>\n\n<p>给你一个 <strong>严格递增</strong> 的正整数数组 <code>arrival</code> ,表示第 <code>i</code> 个任务的到达时间,和另一个数组 <code>load</code> ,其中 <code>load[i]</code> 表示第 <code>i</code> 个请求的工作量(也就是服务器完成它所需要的时间)。你的任务是找到 <strong>最繁忙的服务器</strong> 。最繁忙定义为一个服务器处理的请求数是所有服务器里最多的。</p>\n\n<p>请你返回包含所有 <strong>最繁忙服务器</strong> 序号的列表,你可以以任意顺序返回这个列表。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/10/03/load-1.png\" style=\"height: 221px; width: 389px;\" /></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \n<strong>输出:</strong>[1] \n<strong>解释:</strong>\n所有服务器一开始都是空闲的。\n前 3 个请求分别由前 3 台服务器依次处理。\n请求 3 进来的时候,服务器 0 被占据,所以它呗安排到下一台空闲的服务器,也就是服务器 1 。\n请求 4 进来的时候,由于所有服务器都被占据,该请求被舍弃。\n服务器 0 和 2 分别都处理了一个请求,服务器 1 处理了两个请求。所以服务器 1 是最忙的服务器。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\n<strong>输出:</strong>[0]\n<strong>解释:</strong>\n前 3 个请求分别被前 3 个服务器处理。\n请求 3 进来,由于服务器 0 空闲,它被服务器 0 处理。\n服务器 0 处理了两个请求,服务器 1 和 2 分别处理了一个请求。所以服务器 0 是最忙的服务器。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3], load = [10,12,11]\n<strong>输出:</strong>[0,1,2]\n<strong>解释:</strong>每个服务器分别处理了一个请求,所以它们都是最忙的服务器。\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\n<strong>输出:</strong>[1]\n</pre>\n\n<p><strong>示例 5:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 1, arrival = [1], load = [1]\n<strong>输出:</strong>[0]\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= arrival.length, load.length <= 10<sup>5</sup></code></li>\n\t<li><code>arrival.length == load.length</code></li>\n\t<li><code>1 <= arrival[i], load[i] <= 10<sup>9</sup></code></li>\n\t<li><code>arrival</code> 保证 <strong>严格递增</strong> 。</li>\n</ul>\n",
|
||||
"translatedContent": "<p>你有 <code>k</code> 个服务器,编号为 <code>0</code> 到 <code>k-1</code> ,它们可以同时处理多个请求组。每个服务器有无穷的计算能力但是 <strong>不能同时处理超过一个请求</strong> 。请求分配到服务器的规则如下:</p>\n\n<ul>\n\t<li>第 <code>i</code> (序号从 0 开始)个请求到达。</li>\n\t<li>如果所有服务器都已被占据,那么该请求被舍弃(完全不处理)。</li>\n\t<li>如果第 <code>(i % k)</code> 个服务器空闲,那么对应服务器会处理该请求。</li>\n\t<li>否则,将请求安排给下一个空闲的服务器(服务器构成一个环,必要的话可能从第 0 个服务器开始继续找下一个空闲的服务器)。比方说,如果第 <code>i</code> 个服务器在忙,那么会查看第 <code>(i+1)</code> 个服务器,第 <code>(i+2)</code> 个服务器等等。</li>\n</ul>\n\n<p>给你一个 <strong>严格递增</strong> 的正整数数组 <code>arrival</code> ,表示第 <code>i</code> 个任务的到达时间,和另一个数组 <code>load</code> ,其中 <code>load[i]</code> 表示第 <code>i</code> 个请求的工作量(也就是服务器完成它所需要的时间)。你的任务是找到 <strong>最繁忙的服务器</strong> 。最繁忙定义为一个服务器处理的请求数是所有服务器里最多的。</p>\n\n<p>请你返回包含所有 <strong>最繁忙服务器</strong> 序号的列表,你可以以任意顺序返回这个列表。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/10/03/load-1.png\" style=\"height: 221px; width: 389px;\" /></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4,5], load = [5,2,3,3,3] \n<strong>输出:</strong>[1] \n<strong>解释:</strong>\n所有服务器一开始都是空闲的。\n前 3 个请求分别由前 3 台服务器依次处理。\n请求 3 进来的时候,服务器 0 被占据,所以它被安排到下一台空闲的服务器,也就是服务器 1 。\n请求 4 进来的时候,由于所有服务器都被占据,该请求被舍弃。\n服务器 0 和 2 分别都处理了一个请求,服务器 1 处理了两个请求。所以服务器 1 是最忙的服务器。\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4], load = [1,2,1,2]\n<strong>输出:</strong>[0]\n<strong>解释:</strong>\n前 3 个请求分别被前 3 个服务器处理。\n请求 3 进来,由于服务器 0 空闲,它被服务器 0 处理。\n服务器 0 处理了两个请求,服务器 1 和 2 分别处理了一个请求。所以服务器 0 是最忙的服务器。\n</pre>\n\n<p><strong>示例 3:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3], load = [10,12,11]\n<strong>输出:</strong>[0,1,2]\n<strong>解释:</strong>每个服务器分别处理了一个请求,所以它们都是最忙的服务器。\n</pre>\n\n<p><strong>示例 4:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 3, arrival = [1,2,3,4,8,9,10], load = [5,2,10,3,1,2,2]\n<strong>输出:</strong>[1]\n</pre>\n\n<p><strong>示例 5:</strong></p>\n\n<pre>\n<strong>输入:</strong>k = 1, arrival = [1], load = [1]\n<strong>输出:</strong>[0]\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= arrival.length, load.length <= 10<sup>5</sup></code></li>\n\t<li><code>arrival.length == load.length</code></li>\n\t<li><code>1 <= arrival[i], load[i] <= 10<sup>9</sup></code></li>\n\t<li><code>arrival</code> 保证 <strong>严格递增</strong> 。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
"difficulty": "Hard",
|
||||
"likes": 29,
|
||||
"likes": 140,
|
||||
"dislikes": 0,
|
||||
"isLiked": null,
|
||||
"similarQuestions": "[]",
|
||||
@@ -155,7 +155,7 @@
|
||||
"__typename": "CodeSnippetNode"
|
||||
}
|
||||
],
|
||||
"stats": "{\"totalAccepted\": \"2K\", \"totalSubmission\": \"5.6K\", \"totalAcceptedRaw\": 2040, \"totalSubmissionRaw\": 5638, \"acRate\": \"36.2%\"}",
|
||||
"stats": "{\"totalAccepted\": \"19K\", \"totalSubmission\": \"39.5K\", \"totalAcceptedRaw\": 19033, \"totalSubmissionRaw\": 39512, \"acRate\": \"48.2%\"}",
|
||||
"hints": [
|
||||
"To speed up the next available server search, keep track of the available servers in a sorted structure such as an ordered set.",
|
||||
"To determine if a server is available, keep track of the end times for each task in a heap and add the server to the available set once the soonest task ending time is less than or equal to the next task to add."
|
||||
|
Reference in New Issue
Block a user