mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-03 22:42:52 +08:00
移除零宽空格
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Calculate Digit Sum of a String",
|
||||
"titleSlug": "calculate-digit-sum-of-a-string",
|
||||
"content": "<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>\n\n<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the following:</p>\n\n<ol>\n\t<li><strong>Divide</strong> <code>s</code> into <strong>consecutive groups</strong> of size <code>k</code> such that the first <code>k</code> characters are in the first group, the next <code>k</code> characters are in the second group, and so on. <strong>Note</strong> that the size of the last group can be smaller than <code>k</code>.</li>\n\t<li><strong>Replace</strong> each group of <code>s</code> with a string representing the sum of all its digits. For example, <code>"346"</code> is replaced with <code>"13"</code> because <code>3 + 4 + 6 = 13</code>.</li>\n\t<li><strong>Merge</strong> consecutive groups together to form a new string. If the length of the string is greater than <code>k</code>, repeat from step <code>1</code>.</li>\n</ol>\n\n<p>Return <code>s</code> <em>after all rounds have been completed</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "11111222223", k = 3\n<strong>Output:</strong> "135"\n<strong>Explanation:</strong> \n- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".\n Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. \n So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.\n- For the second round, we divide s into "346" and "5".\n Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. \n So, s becomes "13" + "5" = "135" after second round. \nNow, s.length <= k, so we return "135" as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "00000000", k = 3\n<strong>Output:</strong> "000"\n<strong>Explanation:</strong> \nWe divide s into "000", "000", and "00".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. \ns becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>2 <= k <= 100</code></li>\n\t<li><code>s</code> consists of digits only.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>\n\n<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the following:</p>\n\n<ol>\n\t<li><strong>Divide</strong> <code>s</code> into <strong>consecutive groups</strong> of size <code>k</code> such that the first <code>k</code> characters are in the first group, the next <code>k</code> characters are in the second group, and so on. <strong>Note</strong> that the size of the last group can be smaller than <code>k</code>.</li>\n\t<li><strong>Replace</strong> each group of <code>s</code> with a string representing the sum of all its digits. For example, <code>"346"</code> is replaced with <code>"13"</code> because <code>3 + 4 + 6 = 13</code>.</li>\n\t<li><strong>Merge</strong> consecutive groups together to form a new string. If the length of the string is greater than <code>k</code>, repeat from step <code>1</code>.</li>\n</ol>\n\n<p>Return <code>s</code> <em>after all rounds have been completed</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "11111222223", k = 3\n<strong>Output:</strong> "135"\n<strong>Explanation:</strong> \n- For the first round, we divide s into groups of size 3: "111", "112", "222", and "23".\n Then we calculate the digit sum of each group: 1 + 1 + 1 = 3, 1 + 1 + 2 = 4, 2 + 2 + 2 = 6, and 2 + 3 = 5. \n So, s becomes "3" + "4" + "6" + "5" = "3465" after the first round.\n- For the second round, we divide s into "346" and "5".\n Then we calculate the digit sum of each group: 3 + 4 + 6 = 13, 5 = 5. \n So, s becomes "13" + "5" = "135" after second round. \nNow, s.length <= k, so we return "135" as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "00000000", k = 3\n<strong>Output:</strong> "000"\n<strong>Explanation:</strong> \nWe divide s into "000", "000", and "00".\nThen we calculate the digit sum of each group: 0 + 0 + 0 = 0, 0 + 0 + 0 = 0, and 0 + 0 = 0. \ns becomes "0" + "0" + "0" = "000", whose length is equal to k, so we return "000".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>2 <= k <= 100</code></li>\n\t<li><code>s</code> consists of digits only.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Check if Binary String Has at Most One Segment of Ones",
|
||||
"titleSlug": "check-if-binary-string-has-at-most-one-segment-of-ones",
|
||||
"content": "<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "1001"\n<strong>Output:</strong> false\n<strong>Explanation: </strong>The ones do not form a contiguous segment.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "110"\n<strong>Output:</strong> true</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>\n\t<li><code>s[0]</code> is <code>'1'</code>.</li>\n</ul>\n",
|
||||
"content": "<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "1001"\n<strong>Output:</strong> false\n<strong>Explanation: </strong>The ones do not form a contiguous segment.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "110"\n<strong>Output:</strong> true</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>\n\t<li><code>s[0]</code> is <code>'1'</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Count Good Meals",
|
||||
"titleSlug": "count-good-meals",
|
||||
"content": "<p>A <strong>good meal</strong> is a meal that contains <strong>exactly two different food items</strong> with a sum of deliciousness equal to a power of two.</p>\n\n<p>You can pick <strong>any</strong> two different foods to make a good meal.</p>\n\n<p>Given an array of integers <code>deliciousness</code> where <code>deliciousness[i]</code> is the deliciousness of the <code>i<sup>th</sup></code> item of food, return <em>the number of different <strong>good meals</strong> you can make from this list modulo</em> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p>Note that items with different indices are considered different even if they have the same deliciousness value.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> deliciousness = [1,3,5,7,9]\n<strong>Output:</strong> 4\n<strong>Explanation: </strong>The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> deliciousness = [1,1,1,3,3,3,7]\n<strong>Output:</strong> 15\n<strong>Explanation: </strong>The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= deliciousness.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= deliciousness[i] <= 2<sup>20</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>A <strong>good meal</strong> is a meal that contains <strong>exactly two different food items</strong> with a sum of deliciousness equal to a power of two.</p>\n\n<p>You can pick <strong>any</strong> two different foods to make a good meal.</p>\n\n<p>Given an array of integers <code>deliciousness</code> where <code>deliciousness[i]</code> is the deliciousness of the <code>i<sup>th</sup></code> item of food, return <em>the number of different <strong>good meals</strong> you can make from this list modulo</em> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p>Note that items with different indices are considered different even if they have the same deliciousness value.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> deliciousness = [1,3,5,7,9]\n<strong>Output:</strong> 4\n<strong>Explanation: </strong>The good meals are (1,3), (1,7), (3,5) and, (7,9).\nTheir respective sums are 4, 8, 8, and 16, all of which are powers of 2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> deliciousness = [1,1,1,3,3,3,7]\n<strong>Output:</strong> 15\n<strong>Explanation: </strong>The good meals are (1,1) with 3 ways, (1,3) with 9 ways, and (1,7) with 3 ways.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= deliciousness.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= deliciousness[i] <= 2<sup>20</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Count Pairs With XOR in a Range",
|
||||
"titleSlug": "count-pairs-with-xor-in-a-range",
|
||||
"content": "<p>Given a <strong>(0-indexed)</strong> integer array <code>nums</code> and two integers <code>low</code> and <code>high</code>, return <em>the number of <strong>nice pairs</strong></em>.</p>\r\n\r\n<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 <= i < j < nums.length</code> and <code>low <= (nums[i] XOR nums[j]) <= high</code>.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6\r\n<strong>Output:</strong> 6\r\n<strong>Explanation:</strong> All nice pairs (i, j) are as follows:\r\n - (0, 1): nums[0] XOR nums[1] = 5 \r\n - (0, 2): nums[0] XOR nums[2] = 3\r\n - (0, 3): nums[0] XOR nums[3] = 6\r\n - (1, 2): nums[1] XOR nums[2] = 6\r\n - (1, 3): nums[1] XOR nums[3] = 3\r\n - (2, 3): nums[2] XOR nums[3] = 5\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [9,8,4,2,1], low = 5, high = 14\r\n<strong>Output:</strong> 8\r\n<strong>Explanation:</strong> All nice pairs (i, j) are as follows:\r\n - (0, 2): nums[0] XOR nums[2] = 13\r\n - (0, 3): nums[0] XOR nums[3] = 11\r\n - (0, 4): nums[0] XOR nums[4] = 8\r\n - (1, 2): nums[1] XOR nums[2] = 12\r\n - (1, 3): nums[1] XOR nums[3] = 10\r\n - (1, 4): nums[1] XOR nums[4] = 9\r\n - (2, 3): nums[2] XOR nums[3] = 6\r\n - (2, 4): nums[2] XOR nums[4] = 5</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>\r\n\t<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>\r\n\t<li><code>1 <= low <= high <= 2 * 10<sup>4</sup></code></li>\r\n</ul>",
|
||||
"content": "<p>Given a <strong>(0-indexed)</strong> integer array <code>nums</code> and two integers <code>low</code> and <code>high</code>, return <em>the number of <strong>nice pairs</strong></em>.</p>\r\n\r\n<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 <= i < j < nums.length</code> and <code>low <= (nums[i] XOR nums[j]) <= high</code>.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6\r\n<strong>Output:</strong> 6\r\n<strong>Explanation:</strong> All nice pairs (i, j) are as follows:\r\n - (0, 1): nums[0] XOR nums[1] = 5 \r\n - (0, 2): nums[0] XOR nums[2] = 3\r\n - (0, 3): nums[0] XOR nums[3] = 6\r\n - (1, 2): nums[1] XOR nums[2] = 6\r\n - (1, 3): nums[1] XOR nums[3] = 3\r\n - (2, 3): nums[2] XOR nums[3] = 5\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [9,8,4,2,1], low = 5, high = 14\r\n<strong>Output:</strong> 8\r\n<strong>Explanation:</strong> All nice pairs (i, j) are as follows:\r\n - (0, 2): nums[0] XOR nums[2] = 13\r\n - (0, 3): nums[0] XOR nums[3] = 11\r\n - (0, 4): nums[0] XOR nums[4] = 8\r\n - (1, 2): nums[1] XOR nums[2] = 12\r\n - (1, 3): nums[1] XOR nums[3] = 10\r\n - (1, 4): nums[1] XOR nums[4] = 9\r\n - (2, 3): nums[2] XOR nums[3] = 6\r\n - (2, 4): nums[2] XOR nums[4] = 5</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>\r\n\t<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>\r\n\t<li><code>1 <= low <= high <= 2 * 10<sup>4</sup></code></li>\r\n</ul>",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Count Substrings That Differ by One Character",
|
||||
"titleSlug": "count-substrings-that-differ-by-one-character",
|
||||
"content": "<p>Given two strings <code>s</code> and <code>t</code>, find the number of ways you can choose a non-empty substring of <code>s</code> and replace a <strong>single character</strong> by a different character such that the resulting substring is a substring of <code>t</code>. In other words, find the number of substrings in <code>s</code> that differ from some substring in <code>t</code> by <strong>exactly</strong> one character.</p>\n\n<p>For example, the underlined substrings in <code>"<u>compute</u>r"</code> and <code>"<u>computa</u>tion"</code> only differ by the <code>'e'</code>/<code>'a'</code>, so this is a valid way.</p>\n\n<p>Return <em>the number of substrings that satisfy the condition above.</em></p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aba", t = "baba"\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The following are the pairs of substrings from s and t that differ by exactly 1 character:\n("<u>a</u>ba", "<u>b</u>aba")\n("<u>a</u>ba", "ba<u>b</u>a")\n("ab<u>a</u>", "<u>b</u>aba")\n("ab<u>a</u>", "ba<u>b</u>a")\n("a<u>b</u>a", "b<u>a</u>ba")\n("a<u>b</u>a", "bab<u>a</u>")\nThe underlined portions are the substrings that are chosen from s and t.\n</pre>\n<strong class=\"example\">Example 2:</strong>\n\n<pre>\n<strong>Input:</strong> s = "ab", t = "bb"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The following are the pairs of substrings from s and t that differ by 1 character:\n("<u>a</u>b", "<u>b</u>b")\n("<u>a</u>b", "b<u>b</u>")\n("<u>ab</u>", "<u>bb</u>")\nThe underlined portions are the substrings that are chosen from s and t.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length, t.length <= 100</code></li>\n\t<li><code>s</code> and <code>t</code> consist of lowercase English letters only.</li>\n</ul>\n",
|
||||
"content": "<p>Given two strings <code>s</code> and <code>t</code>, find the number of ways you can choose a non-empty substring of <code>s</code> and replace a <strong>single character</strong> by a different character such that the resulting substring is a substring of <code>t</code>. In other words, find the number of substrings in <code>s</code> that differ from some substring in <code>t</code> by <strong>exactly</strong> one character.</p>\n\n<p>For example, the underlined substrings in <code>"<u>compute</u>r"</code> and <code>"<u>computa</u>tion"</code> only differ by the <code>'e'</code>/<code>'a'</code>, so this is a valid way.</p>\n\n<p>Return <em>the number of substrings that satisfy the condition above.</em></p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aba", t = "baba"\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The following are the pairs of substrings from s and t that differ by exactly 1 character:\n("<u>a</u>ba", "<u>b</u>aba")\n("<u>a</u>ba", "ba<u>b</u>a")\n("ab<u>a</u>", "<u>b</u>aba")\n("ab<u>a</u>", "ba<u>b</u>a")\n("a<u>b</u>a", "b<u>a</u>ba")\n("a<u>b</u>a", "bab<u>a</u>")\nThe underlined portions are the substrings that are chosen from s and t.\n</pre>\n<strong class=\"example\">Example 2:</strong>\n\n<pre>\n<strong>Input:</strong> s = "ab", t = "bb"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The following are the pairs of substrings from s and t that differ by 1 character:\n("<u>a</u>b", "<u>b</u>b")\n("<u>a</u>b", "b<u>b</u>")\n("<u>ab</u>", "<u>bb</u>")\nThe underlined portions are the substrings that are chosen from s and t.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length, t.length <= 100</code></li>\n\t<li><code>s</code> and <code>t</code> consist of lowercase English letters only.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Create Sorted Array through Instructions",
|
||||
"titleSlug": "create-sorted-array-through-instructions",
|
||||
"content": "<p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <strong>cost</strong> of each insertion is the <b>minimum</b> of the following:</p>\r\n\r\n<ul>\r\n\t<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>\r\n\t<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>\r\n</ul>\r\n\r\n<p>For example, if inserting element <code>3</code> into <code>nums = [1,2,3,5]</code>, the <strong>cost</strong> of insertion is <code>min(2, 1)</code> (elements <code>1</code> and <code>2</code> are less than <code>3</code>, element <code>5</code> is greater than <code>3</code>) and <code>nums</code> will become <code>[1,2,3,3,5]</code>.</p>\r\n\r\n<p>Return <em>the <strong>total cost</strong> to insert all elements from </em><code>instructions</code><em> into </em><code>nums</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code></p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,5,6,2]\r\n<strong>Output:</strong> 1\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\r\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\r\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\r\nThe total cost is 0 + 0 + 0 + 1 = 1.</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,2,3,6,5,4]\r\n<strong>Output:</strong> 3\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\r\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\r\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\r\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\r\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 3:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,3,3,3,2,4,2,1,2]\r\n<strong>Output:</strong> 4\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\r\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\r\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\r\nInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\r\nInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\r\nInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= instructions.length <= 10<sup>5</sup></code></li>\r\n\t<li><code>1 <= instructions[i] <= 10<sup>5</sup></code></li>\r\n</ul>",
|
||||
"content": "<p>Given an integer array <code>instructions</code>, you are asked to create a sorted array from the elements in <code>instructions</code>. You start with an empty container <code>nums</code>. For each element from <strong>left to right</strong> in <code>instructions</code>, insert it into <code>nums</code>. The <strong>cost</strong> of each insertion is the <b>minimum</b> of the following:</p>\r\n\r\n<ul>\r\n\t<li>The number of elements currently in <code>nums</code> that are <strong>strictly less than</strong> <code>instructions[i]</code>.</li>\r\n\t<li>The number of elements currently in <code>nums</code> that are <strong>strictly greater than</strong> <code>instructions[i]</code>.</li>\r\n</ul>\r\n\r\n<p>For example, if inserting element <code>3</code> into <code>nums = [1,2,3,5]</code>, the <strong>cost</strong> of insertion is <code>min(2, 1)</code> (elements <code>1</code> and <code>2</code> are less than <code>3</code>, element <code>5</code> is greater than <code>3</code>) and <code>nums</code> will become <code>[1,2,3,3,5]</code>.</p>\r\n\r\n<p>Return <em>the <strong>total cost</strong> to insert all elements from </em><code>instructions</code><em> into </em><code>nums</code>. Since the answer may be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code></p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,5,6,2]\r\n<strong>Output:</strong> 1\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 5 with cost min(1, 0) = 0, now nums = [1,5].\r\nInsert 6 with cost min(2, 0) = 0, now nums = [1,5,6].\r\nInsert 2 with cost min(1, 2) = 1, now nums = [1,2,5,6].\r\nThe total cost is 0 + 0 + 0 + 1 = 1.</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,2,3,6,5,4]\r\n<strong>Output:</strong> 3\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 2 with cost min(1, 0) = 0, now nums = [1,2].\r\nInsert 3 with cost min(2, 0) = 0, now nums = [1,2,3].\r\nInsert 6 with cost min(3, 0) = 0, now nums = [1,2,3,6].\r\nInsert 5 with cost min(3, 1) = 1, now nums = [1,2,3,5,6].\r\nInsert 4 with cost min(3, 2) = 2, now nums = [1,2,3,4,5,6].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 2 = 3.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 3:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> instructions = [1,3,3,3,2,4,2,1,2]\r\n<strong>Output:</strong> 4\r\n<strong>Explanation:</strong> Begin with nums = [].\r\nInsert 1 with cost min(0, 0) = 0, now nums = [1].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3].\r\nInsert 3 with cost min(1, 0) = 0, now nums = [1,3,3,3].\r\nInsert 2 with cost min(1, 3) = 1, now nums = [1,2,3,3,3].\r\nInsert 4 with cost min(5, 0) = 0, now nums = [1,2,3,3,3,4].\r\nInsert 2 with cost min(1, 4) = 1, now nums = [1,2,2,3,3,3,4].\r\nInsert 1 with cost min(0, 6) = 0, now nums = [1,1,2,2,3,3,3,4].\r\nInsert 2 with cost min(2, 4) = 2, now nums = [1,1,2,2,2,3,3,3,4].\r\nThe total cost is 0 + 0 + 0 + 0 + 1 + 0 + 1 + 0 + 2 = 4.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= instructions.length <= 10<sup>5</sup></code></li>\r\n\t<li><code>1 <= instructions[i] <= 10<sup>5</sup></code></li>\r\n</ul>",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Cyclically Rotating a Grid",
|
||||
"titleSlug": "cyclically-rotating-a-grid",
|
||||
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where <code>m</code> and <code>n</code> are both <strong>even</strong> integers, and an integer <code>k</code>.</p>\r\n\r\n<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\" /></p>\r\n\r\n<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\" />\r\n<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\" />\r\n<pre>\r\n<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1\r\n<strong>Output:</strong> [[10,20],[40,30]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\" /></strong>\r\n\r\n<pre>\r\n<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r\n<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>m == grid.length</code></li>\r\n\t<li><code>n == grid[i].length</code></li>\r\n\t<li><code>2 <= m, n <= 50</code></li>\r\n\t<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>\r\n\t<li><code>1 <= grid[i][j] <=<sup> </sup>5000</code></li>\r\n\t<li><code>1 <= k <= 10<sup>9</sup></code></li>\r\n</ul>",
|
||||
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where <code>m</code> and <code>n</code> are both <strong>even</strong> integers, and an integer <code>k</code>.</p>\r\n\r\n<p>The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:</p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid.png\" style=\"width: 231px; height: 258px;\" /></p>\r\n\r\n<p>A cyclic rotation of the matrix is done by cyclically rotating <strong>each layer</strong> in the matrix. To cyclically rotate a layer once, each element in the layer will take the place of the adjacent element in the <strong>counter-clockwise</strong> direction. An example rotation is shown below:</p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/22/explanation_grid.jpg\" style=\"width: 500px; height: 268px;\" />\r\n<p>Return <em>the matrix after applying </em><code>k</code> <em>cyclic rotations to it</em>.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/19/rod2.png\" style=\"width: 421px; height: 191px;\" />\r\n<pre>\r\n<strong>Input:</strong> grid = [[40,10],[30,20]], k = 1\r\n<strong>Output:</strong> [[10,20],[40,30]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n<strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid5.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid6.png\" style=\"width: 231px; height: 262px;\" /></strong> <strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/10/ringofgrid7.png\" style=\"width: 231px; height: 262px;\" /></strong>\r\n\r\n<pre>\r\n<strong>Input:</strong> grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2\r\n<strong>Output:</strong> [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\r\n<strong>Explanation:</strong> The figures above represent the grid at every state.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>m == grid.length</code></li>\r\n\t<li><code>n == grid[i].length</code></li>\r\n\t<li><code>2 <= m, n <= 50</code></li>\r\n\t<li>Both <code>m</code> and <code>n</code> are <strong>even</strong> integers.</li>\r\n\t<li><code>1 <= grid[i][j] <=<sup> </sup>5000</code></li>\r\n\t<li><code>1 <= k <= 10<sup>9</sup></code></li>\r\n</ul>",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Delivering Boxes from Storage to Ports",
|
||||
"titleSlug": "delivering-boxes-from-storage-to-ports",
|
||||
"content": "<p>You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a <strong>limit</strong> on the <strong>number of boxes</strong> and the <strong>total weight</strong> that it can carry.</p>\n\n<p>You are given an array <code>boxes</code>, where <code>boxes[i] = [ports<sub>i</sub>, weight<sub>i</sub>]</code>, and three integers <code>portsCount</code>, <code>maxBoxes</code>, and <code>maxWeight</code>.</p>\n\n<ul>\n\t<li><code>ports<sub>i</sub></code> is the port where you need to deliver the <code>i<sup>th</sup></code> box and <code>weights<sub>i</sub></code> is the weight of the <code>i<sup>th</sup></code> box.</li>\n\t<li><code>portsCount</code> is the number of ports.</li>\n\t<li><code>maxBoxes</code> and <code>maxWeight</code> are the respective box and weight limits of the ship.</li>\n</ul>\n\n<p>The boxes need to be delivered <strong>in the order they are given</strong>. The ship will follow these steps:</p>\n\n<ul>\n\t<li>The ship will take some number of boxes from the <code>boxes</code> queue, not violating the <code>maxBoxes</code> and <code>maxWeight</code> constraints.</li>\n\t<li>For each loaded box <strong>in order</strong>, the ship will make a <strong>trip</strong> to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no <strong>trip</strong> is needed, and the box can immediately be delivered.</li>\n\t<li>The ship then makes a return <strong>trip</strong> to storage to take more boxes from the queue.</li>\n</ul>\n\n<p>The ship must end at storage after all the boxes have been delivered.</p>\n\n<p>Return <em>the <strong>minimum</strong> number of <strong>trips</strong> the ship needs to make to deliver all boxes to their respective ports.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The optimal strategy is as follows: \n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal strategy is as follows: \n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= boxes.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= portsCount, maxBoxes, maxWeight <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= ports<sub>i</sub> <= portsCount</code></li>\n\t<li><code>1 <= weights<sub>i</sub> <= maxWeight</code></li>\n</ul>\n",
|
||||
"content": "<p>You have the task of delivering some boxes from storage to their ports using only one ship. However, this ship has a <strong>limit</strong> on the <strong>number of boxes</strong> and the <strong>total weight</strong> that it can carry.</p>\n\n<p>You are given an array <code>boxes</code>, where <code>boxes[i] = [ports<sub>/sub>, eight<sub>i</sub>]</code>, and three integers <code>portsCount</code>, <code>maxBoxes</code>, and <code>maxWeight</code>.</p>\n\n<ul>\n\t<li><code>ports<sub>i</b></code> is the port where you need to deliver the <code>i<sup>th</sup></code> box and <code>weights<sub>i</sub></code> is the weight of the <code>i<sup>th</sup></code> box.</li>\n\t<li><code>portsCount</code> is the number of ports.</li>\n\t<li><code>maxBoxes</code> and <code>maxWeight</code> are the respective box and weight limits of the ship.</li>\n</ul>\n\n<p>The boxes need to be delivered <strong>in the order they are given</strong>. The ship will follow these steps:</p>\n\n<ul>\n\t<li>The ship will take some number of boxes from the <code>boxes</code> queue, not violating the <code>maxBoxes</code> and <code>maxWeight</code> constraints.</li>\n\t<li>For each loaded box <strong>in order</strong>, the ship will make a <strong>trip</strong> to the port the box needs to be delivered to and deliver it. If the ship is already at the correct port, no <strong>trip</strong> is needed, and the box can immediately be delivered.</li>\n\t<li>The ship then makes a return <strong>trip</strong> to storage to take more boxes from the queue.</li>\n</ul>\n\n<p>The ship must end at storage after all the boxes have been delivered.</p>\n\n<p>Return <em>the <strong>minimum</strong> number of <strong>trips</strong> the ship needs to make to deliver all boxes to their respective ports.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,1],[2,1],[1,1]], portsCount = 2, maxBoxes = 3, maxWeight = 3\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The optimal strategy is as follows: \n- The ship takes all the boxes in the queue, goes to port 1, then port 2, then port 1 again, then returns to storage. 4 trips.\nSo the total number of trips is 4.\nNote that the first and third boxes cannot be delivered together because the boxes need to be delivered in order (i.e. the second box needs to be delivered at port 2 before the third box).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,2],[3,3],[3,1],[3,1],[2,4]], portsCount = 3, maxBoxes = 3, maxWeight = 6\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal strategy is as follows: \n- The ship takes the first box, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the second, third and fourth boxes, goes to port 3, then returns to storage. 2 trips.\n- The ship takes the fifth box, goes to port 2, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> boxes = [[1,4],[1,2],[2,1],[2,1],[3,2],[3,4]], portsCount = 3, maxBoxes = 6, maxWeight = 7\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal strategy is as follows:\n- The ship takes the first and second boxes, goes to port 1, then returns to storage. 2 trips.\n- The ship takes the third and fourth boxes, goes to port 2, then returns to storage. 2 trips.\n- The ship takes the fifth and sixth boxes, goes to port 3, then returns to storage. 2 trips.\nSo the total number of trips is 2 + 2 + 2 = 6.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= boxes.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= portsCount, maxBoxes, maxWeight <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= ports<sub>i</su <= portsCount</code></li>\n\t<li><code>1 <= weights<sub>i</sub> <= maxWeight</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Equal Sum Arrays With Minimum Number of Operations",
|
||||
"titleSlug": "equal-sum-arrays-with-minimum-number-of-operations",
|
||||
"content": "<p>You are given two arrays of integers <code>nums1</code> and <code><font face=\"monospace\">nums2</font></code>, possibly of different lengths. The values in the arrays are between <code>1</code> and <code>6</code>, inclusive.</p>\n\n<p>In one operation, you can change any integer's value in <strong>any </strong>of the arrays to <strong>any</strong> value between <code>1</code> and <code>6</code>, inclusive.</p>\n\n<p>Return <em>the minimum number of operations required to make the sum of values in </em><code>nums1</code><em> equal to the sum of values in </em><code>nums2</code><em>.</em> Return <code>-1</code> if it is not possible to make the sum of the two arrays equal.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [<u><strong>6</strong></u>,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,<strong><u>1</u></strong>], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,<strong><u>2</u></strong>,4,5,1], nums2 = [6,1,2,2,2,2].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,1,1,1,1,1,1], nums2 = [6]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [6,6], nums2 = [1]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. \n- Change nums1[0] to 2. nums1 = [<strong><u>2</u></strong>,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,<strong><u>2</u></strong>], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [<strong><u>4</u></strong>].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i], nums2[i] <= 6</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given two arrays of integers <code>nums1</code> and <code><font face=\"monospace\">nums2</font></code>, possibly of different lengths. The values in the arrays are between <code>1</code> and <code>6</code>, inclusive.</p>\n\n<p>In one operation, you can change any integer's value in <strong>any </strong>of the arrays to <strong>any</strong> value between <code>1</code> and <code>6</code>, inclusive.</p>\n\n<p>Return <em>the minimum number of operations required to make the sum of values in </em><code>nums1</code><em> equal to the sum of values in </em><code>nums2</code><em>.</em> Return <code>-1</code> if it is not possible to make the sum of the two arrays equal.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.\n- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [<u><strong>6</strong></u>,1,2,2,2,2].\n- Change nums1[5] to 1. nums1 = [1,2,3,4,5,<strong><u>1</u></strong>], nums2 = [6,1,2,2,2,2].\n- Change nums1[2] to 2. nums1 = [1,2,<strong><u>2</u></strong>,4,5,1], nums2 = [6,1,2,2,2,2].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,1,1,1,1,1,1], nums2 = [6]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [6,6], nums2 = [1]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. \n- Change nums1[0] to 2. nums1 = [<strong><u>2</u></strong>,6], nums2 = [1].\n- Change nums1[1] to 2. nums1 = [2,<strong><u>2</u></strong>], nums2 = [1].\n- Change nums2[0] to 4. nums1 = [2,2], nums2 = [<strong><u>4</u></strong>].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i], nums2[i] <= 6</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Find All People With Secret",
|
||||
"titleSlug": "find-all-people-with-secret",
|
||||
"content": "<p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates that person <code>x<sub>i</sub></code> and person <code>y<sub>i</sub></code> have a meeting at <code>time<sub>i</sub></code>. A person may attend <strong>multiple meetings</strong> at the same time. Finally, you are given an integer <code>firstPerson</code>.</p>\n\n<p>Person <code>0</code> has a <strong>secret</strong> and initially shares the secret with a person <code>firstPerson</code> at time <code>0</code>. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person <code>x<sub>i</sub></code> has the secret at <code>time<sub>i</sub></code>, then they will share the secret with person <code>y<sub>i</sub></code>, and vice versa.</p>\n\n<p>The secrets are shared <strong>instantaneously</strong>. That is, a person may receive the secret and share it with people in other meetings within the same time frame.</p>\n\n<p>Return <em>a list of all the people that have the secret after all the meetings have taken place. </em>You may return the answer in <strong>any order</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,5]\n<strong>Explanation:\n</strong>At time 0, person 0 shares the secret with person 1.\nAt time 5, person 1 shares the secret with person 2.\nAt time 8, person 2 shares the secret with person 3.\nAt time 10, person 1 shares the secret with person 5.\nThus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3\n<strong>Output:</strong> [0,1,3]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 3.\nAt time 2, neither person 1 nor person 2 know the secret.\nAt time 3, person 3 shares the secret with person 0 and person 1.\nThus, people 0, 1, and 3 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,4]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 1.\nAt time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\nNote that person 2 can share the secret at the same time as receiving it.\nAt time 2, person 3 shares the secret with person 4.\nThus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= meetings.length <= 10<sup>5</sup></code></li>\n\t<li><code>meetings[i].length == 3</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i </sub><= n - 1</code></li>\n\t<li><code>x<sub>i</sub> != y<sub>i</sub></code></li>\n\t<li><code>1 <= time<sub>i</sub> <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= firstPerson <= n - 1</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates that person <code>x<sub>i</sub></code> and person <code>y<sub>i</sub></code> have a meeting at <code>time<sub>i</sub></code>. A person may attend <strong>multiple meetings</strong> at the same time. Finally, you are given an integer <code>firstPerson</code>.</p>\n\n<p>Person <code>0</code> has a <strong>secret</strong> and initially shares the secret with a person <code>firstPerson</code> at time <code>0</code>. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person <code>x<sub>i</sub></code> has the secret at <code>time<sub>i</sub></code>, then they will share the secret with person <code>y<sub>i</sub></code>, and vice versa.</p>\n\n<p>The secrets are shared <strong>instantaneously</strong>. That is, a person may receive the secret and share it with people in other meetings within the same time frame.</p>\n\n<p>Return <em>a list of all the people that have the secret after all the meetings have taken place. </em>You may return the answer in <strong>any order</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,5]\n<strong>Explanation:\n</strong>At time 0, person 0 shares the secret with person 1.\nAt time 5, person 1 shares the secret with person 2.\nAt time 8, person 2 shares the secret with person 3.\nAt time 10, person 1 shares the secret with person 5.\nThus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3\n<strong>Output:</strong> [0,1,3]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 3.\nAt time 2, neither person 1 nor person 2 know the secret.\nAt time 3, person 3 shares the secret with person 0 and person 1.\nThus, people 0, 1, and 3 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,4]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 1.\nAt time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\nNote that person 2 can share the secret at the same time as receiving it.\nAt time 2, person 3 shares the secret with person 4.\nThus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= meetings.length <= 10<sup>5</sup></code></li>\n\t<li><code>meetings[i].length == 3</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i </sub><= n - 1</code></li>\n\t<li><code>x<sub>i</sub> != y<sub>i</sub></code></li>\n\t<li><code>1 <= time<sub>i</sub> <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= firstPerson <= n - 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Find the Highest Altitude",
|
||||
"titleSlug": "find-the-highest-altitude",
|
||||
"content": "<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>\n\n<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the <strong>net gain in altitude</strong> between points <code>i</code> and <code>i + 1</code> for all (<code>0 <= i < n)</code>. Return <em>the <strong>highest altitude</strong> of a point.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> gain = [-5,1,5,0,-7]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> gain = [-4,-3,-2,-1,4,3,2]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == gain.length</code></li>\n\t<li><code>1 <= n <= 100</code></li>\n\t<li><code>-100 <= gain[i] <= 100</code></li>\n</ul>\n",
|
||||
"content": "<p>There is a biker going on a road trip. The road trip consists of <code>n + 1</code> points at different altitudes. The biker starts his trip on point <code>0</code> with altitude equal <code>0</code>.</p>\n\n<p>You are given an integer array <code>gain</code> of length <code>n</code> where <code>gain[i]</code> is the <strong>net gain in altitude</strong> between points <code>i</code> and <code>i + 1</code> for all (<code>0 <= i < n)</code>. Return <em>the <strong>highest altitude</strong> of a point.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> gain = [-5,1,5,0,-7]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> gain = [-4,-3,-2,-1,4,3,2]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == gain.length</code></li>\n\t<li><code>1 <= n <= 100</code></li>\n\t<li><code>-100 <= gain[i] <= 100</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Get Biggest Three Rhombus Sums in a Grid",
|
||||
"titleSlug": "get-biggest-three-rhombus-sums-in-a-grid",
|
||||
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>\n\n<p>A <strong>rhombus sum</strong> is the sum of the elements that form <strong>the</strong> <strong>border</strong> of a regular rhombus shape in <code>grid</code>. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each <strong>rhombus sum</strong>:</p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png\" style=\"width: 385px; height: 385px;\" />\n<p>Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.</p>\n\n<p>Return <em>the biggest three <strong>distinct rhombus sums</strong> in the </em><code>grid</code><em> in <strong>descending order</strong></em><em>. If there are less than three distinct values, return all of them</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex1.png\" style=\"width: 360px; height: 361px;\" />\n<pre>\n<strong>Input:</strong> grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\n<strong>Output:</strong> [228,216,211]\n<strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex2.png\" style=\"width: 217px; height: 217px;\" />\n<pre>\n<strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]\n<strong>Output:</strong> [20,9,8]\n<strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [[7,7,7]]\n<strong>Output:</strong> [7]\n<strong>Explanation:</strong> All three possible rhombus sums are the same, so return [7].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 50</code></li>\n\t<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>\n\n<p>A <strong>rhombus sum</strong> is the sum of the elements that form <strong>the</strong> <strong>border</strong> of a regular rhombus shape in <code>grid</code>. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each <strong>rhombus sum</strong>:</p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png\" style=\"width: 385px; height: 385px;\" />\n<p>Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.</p>\n\n<p>Return <em>the biggest three <strong>distinct rhombus sums</strong> in the </em><code>grid</code><em> in <strong>descending order</strong></em><em>. If there are less than three distinct values, return all of them</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex1.png\" style=\"width: 360px; height: 361px;\" />\n<pre>\n<strong>Input:</strong> grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]\n<strong>Output:</strong> [228,216,211]\n<strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 20 + 3 + 200 + 5 = 228\n- Red: 200 + 2 + 10 + 4 = 216\n- Green: 5 + 200 + 4 + 2 = 211\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex2.png\" style=\"width: 217px; height: 217px;\" />\n<pre>\n<strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]\n<strong>Output:</strong> [20,9,8]\n<strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.\n- Blue: 4 + 2 + 6 + 8 = 20\n- Red: 9 (area 0 rhombus in the bottom right corner)\n- Green: 8 (area 0 rhombus in the bottom middle)\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [[7,7,7]]\n<strong>Output:</strong> [7]\n<strong>Explanation:</strong> All three possible rhombus sums are the same, so return [7].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 50</code></li>\n\t<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Get Maximum in Generated Array",
|
||||
"titleSlug": "get-maximum-in-generated-array",
|
||||
"content": "<p>You are given an integer <code>n</code>. A <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n + 1</code> is generated in the following way:</p>\n\n<ul>\n\t<li><code>nums[0] = 0</code></li>\n\t<li><code>nums[1] = 1</code></li>\n\t<li><code>nums[2 * i] = nums[i]</code> when <code>2 <= 2 * i <= n</code></li>\n\t<li><code>nums[2 * i + 1] = nums[i] + nums[i + 1]</code> when <code>2 <= 2 * i + 1 <= n</code></li>\n</ul>\n\n<p>Return<strong> </strong><em>the <strong>maximum</strong> integer in the array </em><code>nums</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 7\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> According to the given rules:\n nums[0] = 0\n nums[1] = 1\n nums[(1 * 2) = 2] = nums[1] = 1\n nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n nums[(2 * 2) = 4] = nums[2] = 1\n nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n nums[(3 * 2) = 6] = nums[3] = 2\n nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= n <= 100</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an integer <code>n</code>. A <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n + 1</code> is generated in the following way:</p>\n\n<ul>\n\t<li><code>nums[0] = 0</code></li>\n\t<li><code>nums[1] = 1</code></li>\n\t<li><code>nums[2 * i] = nums[i]</code> when <code>2 <= 2 * i <= n</code></li>\n\t<li><code>nums[2 * i + 1] = nums[i] + nums[i + 1]</code> when <code>2 <= 2 * i + 1 <= n</code></li>\n</ul>\n\n<p>Return<strong> </strong><em>the <strong>maximum</strong> integer in the array </em><code>nums</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 7\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> According to the given rules:\n nums[0] = 0\n nums[1] = 1\n nums[(1 * 2) = 2] = nums[1] = 1\n nums[(1 * 2) + 1 = 3] = nums[1] + nums[2] = 1 + 1 = 2\n nums[(2 * 2) = 4] = nums[2] = 1\n nums[(2 * 2) + 1 = 5] = nums[2] + nums[3] = 1 + 2 = 3\n nums[(3 * 2) = 6] = nums[3] = 2\n nums[(3 * 2) + 1 = 7] = nums[3] + nums[4] = 2 + 1 = 3\nHence, nums = [0,1,1,2,1,3,2,3], and the maximum is max(0,1,1,2,1,3,2,3) = 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> According to the given rules, nums = [0,1,1]. The maximum is max(0,1,1) = 1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> According to the given rules, nums = [0,1,1,2]. The maximum is max(0,1,1,2) = 2.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= n <= 100</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Kth Smallest Instructions",
|
||||
"titleSlug": "kth-smallest-instructions",
|
||||
"content": "<p>Bob is standing at cell <code>(0, 0)</code>, and he wants to reach <code>destination</code>: <code>(row, column)</code>. He can only travel <strong>right</strong> and <strong>down</strong>. You are going to help Bob by providing <strong>instructions</strong> for him to reach <code>destination</code>.</p>\n\n<p>The <strong>instructions</strong> are represented as a string, where each character is either:</p>\n\n<ul>\n\t<li><code>'H'</code>, meaning move horizontally (go <strong>right</strong>), or</li>\n\t<li><code>'V'</code>, meaning move vertically (go <strong>down</strong>).</li>\n</ul>\n\n<p>Multiple <strong>instructions</strong> will lead Bob to <code>destination</code>. For example, if <code>destination</code> is <code>(2, 3)</code>, both <code>"HHHVV"</code> and <code>"HVHVH"</code> are valid <strong>instructions</strong>.</p>\n\n<p>However, Bob is very picky. Bob has a lucky number <code>k</code>, and he wants the <code>k<sup>th</sup></code> <strong>lexicographically smallest instructions</strong> that will lead him to <code>destination</code>. <code>k</code> is <strong>1-indexed</strong>.</p>\n\n<p>Given an integer array <code>destination</code> and an integer <code>k</code>, return <em>the </em><code>k<sup>th</sup></code><em> <strong>lexicographically smallest instructions</strong> that will take Bob to </em><code>destination</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex1.png\" style=\"width: 300px; height: 229px;\" /></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 1\n<strong>Output:</strong> "HHHVV"\n<strong>Explanation:</strong> All the instructions that reach (2, 3) in lexicographic order are as follows:\n["HHHVV", "HHVHV", "HHVVH", "HVHHV", "HVHVH", "HVVHH", "VHHHV", "VHHVH", "VHVHH", "VVHHH"].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex2.png\" style=\"width: 300px; height: 229px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 2\n<strong>Output:</strong> "HHVHV"\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex3.png\" style=\"width: 300px; height: 229px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 3\n<strong>Output:</strong> "HHVVH"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>destination.length == 2</code></li>\n\t<li><code>1 <= row, column <= 15</code></li>\n\t<li><code>1 <= k <= nCr(row + column, row)</code>, where <code>nCr(a, b)</code> denotes <code>a</code> choose <code>b</code>.</li>\n</ul>\n",
|
||||
"content": "<p>Bob is standing at cell <code>(0, 0)</code>, and he wants to reach <code>destination</code>: <code>(row, column)</code>. He can only travel <strong>right</strong> and <strong>down</strong>. You are going to help Bob by providing <strong>instructions</strong> for him to reach <code>destination</code>.</p>\n\n<p>The <strong>instructions</strong> are represented as a string, where each character is either:</p>\n\n<ul>\n\t<li><code>'H'</code>, meaning move horizontally (go <strong>right</strong>), or</li>\n\t<li><code>'V'</code>, meaning move vertically (go <strong>down</strong>).</li>\n</ul>\n\n<p>Multiple <strong>instructions</strong> will lead Bob to <code>destination</code>. For example, if <code>destination</code> is <code>(2, 3)</code>, both <code>"HHHVV"</code> and <code>"HVHVH"</code> are valid <strong>instructions</strong>.</p>\n\n<p>However, Bob is very picky. Bob has a lucky number <code>k</code>, and he wants the <code>k<sup>th</sup></code> <strong>lexicographically smallest instructions</strong> that will lead him to <code>destination</code>. <code>k</code> is <strong>1-indexed</strong>.</p>\n\n<p>Given an integer array <code>destination</code> and an integer <code>k</code>, return <em>the </em><code>k<sup>th</sup></code><em> <strong>lexicographically smallest instructions</strong> that will take Bob to </em><code>destination</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex1.png\" style=\"width: 300px; height: 229px;\" /></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 1\n<strong>Output:</strong> "HHHVV"\n<strong>Explanation:</strong> All the instructions that reach (2, 3) in lexicographic order are as follows:\n["HHHVV", "HHVHV", "HHVVH", "HVHHV", "HVHVH", "HVVHH", "VHHHV", "VHHVH", "VHVHH", "VVHHH"].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex2.png\" style=\"width: 300px; height: 229px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 2\n<strong>Output:</strong> "HHVHV"\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/12/ex3.png\" style=\"width: 300px; height: 229px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> destination = [2,3], k = 3\n<strong>Output:</strong> "HHVVH"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>destination.length == 2</code></li>\n\t<li><code>1 <= row, column <= 15</code></li>\n\t<li><code>1 <= k <= nCr(row + column, row)</code>, where <code>nCr(a, b)</code> denotes <code>a</code> choose <code>b</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Lexicographically Smallest String After Applying Operations",
|
||||
"titleSlug": "lexicographically-smallest-string-after-applying-operations",
|
||||
"content": "<p>You are given a string <code>s</code> of <strong>even length</strong> consisting of digits from <code>0</code> to <code>9</code>, and two integers <code>a</code> and <code>b</code>.</p>\n\n<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>\n\n<ul>\n\t<li>Add <code>a</code> to all odd indices of <code>s</code> <strong>(0-indexed)</strong>. Digits post <code>9</code> are cycled back to <code>0</code>. For example, if <code>s = "3456"</code> and <code>a = 5</code>, <code>s</code> becomes <code>"3951"</code>.</li>\n\t<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = "3456"</code> and <code>b = 1</code>, <code>s</code> becomes <code>"6345"</code>.</li>\n</ul>\n\n<p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain by applying the above operations any number of times on</em> <code>s</code>.</p>\n\n<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>. For example, <code>"0158"</code> is lexicographically smaller than <code>"0190"</code> because the first position they differ is at the third letter, and <code>'5'</code> comes before <code>'9'</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "5525", a = 9, b = 2\n<strong>Output:</strong> "2050"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "5525"\nRotate: "2555"\nAdd: "2454"\nAdd: "2353"\nRotate: "5323"\nAdd: "5222"\nAdd: "5121"\nRotate: "2151"\nAdd: "2050"\nThere is no way to obtain a string that is lexicographically smaller than "2050".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "74", a = 5, b = 1\n<strong>Output:</strong> "24"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "74"\nRotate: "47"\nAdd: "42"\nRotate: "24"\nThere is no way to obtain a string that is lexicographically smaller than "24".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "0011", a = 4, b = 2\n<strong>Output:</strong> "0011"\n<strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than "0011".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> is even.</li>\n\t<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> of <strong>even length</strong> consisting of digits from <code>0</code> to <code>9</code>, and two integers <code>a</code> and <code>b</code>.</p>\n\n<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>\n\n<ul>\n\t<li>Add <code>a</code> to all odd indices of <code>s</code> <strong>(0-indexed)</strong>. Digits post <code>9</code> are cycled back to <code>0</code>. For example, if <code>s = "3456"</code> and <code>a = 5</code>, <code>s</code> becomes <code>"3951"</code>.</li>\n\t<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = "3456"</code> and <code>b = 1</code>, <code>s</code> becomes <code>"6345"</code>.</li>\n</ul>\n\n<p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain by applying the above operations any number of times on</em> <code>s</code>.</p>\n\n<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>. For example, <code>"0158"</code> is lexicographically smaller than <code>"0190"</code> because the first position they differ is at the third letter, and <code>'5'</code> comes before <code>'9'</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "5525", a = 9, b = 2\n<strong>Output:</strong> "2050"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "5525"\nRotate: "2555"\nAdd: "2454"\nAdd: "2353"\nRotate: "5323"\nAdd: "5222"\nAdd: "5121"\nRotate: "2151"\nAdd: "2050"\nThere is no way to obtain a string that is lexicographically smaller than "2050".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "74", a = 5, b = 1\n<strong>Output:</strong> "24"\n<strong>Explanation:</strong> We can apply the following operations:\nStart: "74"\nRotate: "47"\nAdd: "42"\nRotate: "24"\nThere is no way to obtain a string that is lexicographically smaller than "24".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "0011", a = 4, b = 2\n<strong>Output:</strong> "0011"\n<strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than "0011".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= s.length <= 100</code></li>\n\t<li><code>s.length</code> is even.</li>\n\t<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>\n\t<li><code>1 <= a <= 9</code></li>\n\t<li><code>1 <= b <= s.length - 1</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Make the XOR of All Segments Equal to Zero",
|
||||
"titleSlug": "make-the-xor-of-all-segments-equal-to-zero",
|
||||
"content": "<p>You are given an array <code>nums</code> and an integer <code>k</code>. The <font face=\"monospace\">XOR</font> of a segment <code>[left, right]</code> where <code>left <= right</code> is the <code>XOR</code> of all the elements with indices between <code>left</code> and <code>right</code>, inclusive: <code>nums[left] XOR nums[left+1] XOR ... XOR nums[right]</code>.</p>\n\n<p>Return <em>the minimum number of elements to change in the array </em>such that the <code>XOR</code> of all segments of size <code>k</code> is equal to zero.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,0,3,0], k = 1\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [<u><strong>1</strong></u>,<u><strong>2</strong></u>,0,<u><strong>3</strong></u>,0] to from [<u><strong>0</strong></u>,<u><strong>0</strong></u>,0,<u><strong>0</strong></u>,0].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,4,5,2,1,7,3,4,7], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [3,4,<strong><u>5</u></strong>,<strong><u>2</u></strong>,<strong><u>1</u></strong>,7,3,4,7] to [3,4,<strong><u>7</u></strong>,<strong><u>3</u></strong>,<strong><u>4</u></strong>,7,3,4,7].\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,4,1,2,5,1,2,6], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [1,2,<strong><u>4,</u></strong>1,2,<strong><u>5</u></strong>,1,2,<strong><u>6</u></strong>] to [1,2,<strong><u>3</u></strong>,1,2,<strong><u>3</u></strong>,1,2,<strong><u>3</u></strong>].</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] < 2<sup>10</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an array <code>nums</code> and an integer <code>k</code>. The <font face=\"monospace\">XOR</font> of a segment <code>[left, right]</code> where <code>left <= right</code> is the <code>XOR</code> of all the elements with indices between <code>left</code> and <code>right</code>, inclusive: <code>nums[left] XOR nums[left+1] XOR ... XOR nums[right]</code>.</p>\n\n<p>Return <em>the minimum number of elements to change in the array </em>such that the <code>XOR</code> of all segments of size <code>k</code> is equal to zero.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,0,3,0], k = 1\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [<u><strong>1</strong></u>,<u><strong>2</strong></u>,0,<u><strong>3</strong></u>,0] to from [<u><strong>0</strong></u>,<u><strong>0</strong></u>,0,<u><strong>0</strong></u>,0].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,4,5,2,1,7,3,4,7], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [3,4,<strong><u>5</u></strong>,<strong><u>2</u></strong>,<strong><u>1</u></strong>,7,3,4,7] to [3,4,<strong><u>7</u></strong>,<strong><u>3</u></strong>,<strong><u>4</u></strong>,7,3,4,7].\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,4,1,2,5,1,2,6], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>Modify the array from [1,2,<strong><u>4,</u></strong>1,2,<strong><u>5</u></strong>,1,2,<strong><u>6</u></strong>] to [1,2,<strong><u>3</u></strong>,1,2,<strong><u>3</u></strong>,1,2,<strong><u>3</u></strong>].</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= nums.length <= 2000</code></li>\n\t<li><code>0 <= nums[i] < 2<sup>10</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum Distance Between a Pair of Values",
|
||||
"titleSlug": "maximum-distance-between-a-pair-of-values",
|
||||
"content": "<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code> and <code>nums2</code>.</p>\n\n<p>A pair of indices <code>(i, j)</code>, where <code>0 <= i < nums1.length</code> and <code>0 <= j < nums2.length</code>, is <strong>valid</strong> if both <code>i <= j</code> and <code>nums1[i] <= nums2[j]</code>. The <strong>distance</strong> of the pair is <code>j - i</code>.</p>\n\n<p>Return <em>the <strong>maximum distance</strong> of any <strong>valid</strong> pair </em><code>(i, j)</code><em>. If there are no valid pairs, return </em><code>0</code>.</p>\n\n<p>An array <code>arr</code> is <strong>non-increasing</strong> if <code>arr[i-1] >= arr[i]</code> for every <code>1 <= i < arr.length</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [2,2,2], nums2 = [10,10,1]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i], nums2[j] <= 10<sup>5</sup></code></li>\n\t<li>Both <code>nums1</code> and <code>nums2</code> are <strong>non-increasing</strong>.</li>\n</ul>\n",
|
||||
"content": "<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code> and <code>nums2</code>.</p>\n\n<p>A pair of indices <code>(i, j)</code>, where <code>0 <= i < nums1.length</code> and <code>0 <= j < nums2.length</code>, is <strong>valid</strong> if both <code>i <= j</code> and <code>nums1[i] <= nums2[j]</code>. The <strong>distance</strong> of the pair is <code>j - i</code>.</p>\n\n<p>Return <em>the <strong>maximum distance</strong> of any <strong>valid</strong> pair </em><code>(i, j)</code><em>. If there are no valid pairs, return </em><code>0</code>.</p>\n\n<p>An array <code>arr</code> is <strong>non-increasing</strong> if <code>arr[i-1] >= arr[i]</code> for every <code>1 <= i < arr.length</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [55,30,5,4,2], nums2 = [100,20,10,10,5]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The valid pairs are (0,0), (2,2), (2,3), (2,4), (3,3), (3,4), and (4,4).\nThe maximum distance is 2 with pair (2,4).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [2,2,2], nums2 = [10,10,1]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The valid pairs are (0,0), (0,1), and (1,1).\nThe maximum distance is 1 with pair (0,1).\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [30,29,19,5], nums2 = [25,25,25,25,25]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The valid pairs are (2,2), (2,3), (2,4), (3,3), and (3,4).\nThe maximum distance is 2 with pair (2,4).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length, nums2.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i], nums2[j] <= 10<sup>5</sup></code></li>\n\t<li>Both <code>nums1</code> and <code>nums2</code> are <strong>non-increasing</strong>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum Number of Weeks for Which You Can Work",
|
||||
"titleSlug": "maximum-number-of-weeks-for-which-you-can-work",
|
||||
"content": "<p>There are <code>n</code> projects numbered from <code>0</code> to <code>n - 1</code>. You are given an integer array <code>milestones</code> where each <code>milestones[i]</code> denotes the number of milestones the <code>i<sup>th</sup></code> project has.</p>\n\n<p>You can work on the projects following these two rules:</p>\n\n<ul>\n\t<li>Every week, you will finish <strong>exactly one</strong> milestone of <strong>one</strong> project. You <strong>must</strong> work every week.</li>\n\t<li>You <strong>cannot</strong> work on two milestones from the same project for two <strong>consecutive</strong> weeks.</li>\n</ul>\n\n<p>Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will <strong>stop working</strong>. Note that you may not be able to finish every project's milestones due to these constraints.</p>\n\n<p>Return <em>the <strong>maximum</strong> number of weeks you would be able to work on the projects without violating the rules mentioned above</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> milestones = [1,2,3]\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> One possible scenario is:\n- During the 1<sup>st</sup> week, you will work on a milestone of project 0.\n- During the 2<sup>nd</sup> week, you will work on a milestone of project 2.\n- During the 3<sup>rd</sup> week, you will work on a milestone of project 1.\n- During the 4<sup>th</sup> week, you will work on a milestone of project 2.\n- During the 5<sup>th</sup> week, you will work on a milestone of project 1.\n- During the 6<sup>th</sup> week, you will work on a milestone of project 2.\nThe total number of weeks is 6.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> milestones = [5,2,1]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> One possible scenario is:\n- During the 1<sup>st</sup> week, you will work on a milestone of project 0.\n- During the 2<sup>nd</sup> week, you will work on a milestone of project 1.\n- During the 3<sup>rd</sup> week, you will work on a milestone of project 0.\n- During the 4<sup>th</sup> week, you will work on a milestone of project 1.\n- During the 5<sup>th</sup> week, you will work on a milestone of project 0.\n- During the 6<sup>th</sup> week, you will work on a milestone of project 2.\n- During the 7<sup>th</sup> week, you will work on a milestone of project 0.\nThe total number of weeks is 7.\nNote that you cannot work on the last milestone of project 0 on 8<sup>th</sup> week because it would violate the rules.\nThus, one milestone in project 0 will remain unfinished.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == milestones.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= milestones[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>There are <code>n</code> projects numbered from <code>0</code> to <code>n - 1</code>. You are given an integer array <code>milestones</code> where each <code>milestones[i]</code> denotes the number of milestones the <code>i<sup>th</sup></code> project has.</p>\n\n<p>You can work on the projects following these two rules:</p>\n\n<ul>\n\t<li>Every week, you will finish <strong>exactly one</strong> milestone of <strong>one</strong> project. You <strong>must</strong> work every week.</li>\n\t<li>You <strong>cannot</strong> work on two milestones from the same project for two <strong>consecutive</strong> weeks.</li>\n</ul>\n\n<p>Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will <strong>stop working</strong>. Note that you may not be able to finish every project's milestones due to these constraints.</p>\n\n<p>Return <em>the <strong>maximum</strong> number of weeks you would be able to work on the projects without violating the rules mentioned above</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> milestones = [1,2,3]\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> One possible scenario is:\n- During the 1<sup>st</sup> week, you will work on a milestone of project 0.\n- During the 2<sup>nd</sup> week, you will work on a milestone of project 2.\n- During the 3<sup>rd</sup> week, you will work on a milestone of project 1.\n- During the 4<sup>th</sup> week, you will work on a milestone of project 2.\n- During the 5<sup>th</sup> week, you will work on a milestone of project 1.\n- During the 6<sup>th</sup> week, you will work on a milestone of project 2.\nThe total number of weeks is 6.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> milestones = [5,2,1]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> One possible scenario is:\n- During the 1<sup>st</sup> week, you will work on a milestone of project 0.\n- During the 2<sup>nd</sup> week, you will work on a milestone of project 1.\n- During the 3<sup>rd</sup> week, you will work on a milestone of project 0.\n- During the 4<sup>th</sup> week, you will work on a milestone of project 1.\n- During the 5<sup>th</sup> week, you will work on a milestone of project 0.\n- During the 6<sup>th</sup> week, you will work on a milestone of project 2.\n- During the 7<sup>th</sup> week, you will work on a milestone of project 0.\nThe total number of weeks is 7.\nNote that you cannot work on the last milestone of project 0 on 8<sup>th</sup> week because it would violate the rules.\nThus, one milestone in project 0 will remain unfinished.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == milestones.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= milestones[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum Score From Removing Stones",
|
||||
"titleSlug": "maximum-score-from-removing-stones",
|
||||
"content": "<p>You are playing a solitaire game with <strong>three piles</strong> of stones of sizes <code>a</code>, <code>b</code>, and <code>c</code> respectively. Each turn you choose two <strong>different non-empty </strong>piles, take one stone from each, and add <code>1</code> point to your score. The game stops when there are <strong>fewer than two non-empty</strong> piles (meaning there are no more available moves).</p>\n\n<p>Given three integers <code>a</code>, <code>b</code>, and <code>c</code>, return <em>the</em> <strong><em>maximum</em> </strong><em><strong>score</strong> you can get.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 2, b = 4, c = 6\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 4, b = 4, c = 6\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 1, b = 8, c = 8\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= a, b, c <= 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are playing a solitaire game with <strong>three piles</strong> of stones of sizes <code>a</code>, <code>b</code>, and <code>c</code> respectively. Each turn you choose two <strong>different non-empty </strong>piles, take one stone from each, and add <code>1</code> point to your score. The game stops when there are <strong>fewer than two non-empty</strong> piles (meaning there are no more available moves).</p>\n\n<p>Given three integers <code>a</code>, <code>b</code>, and <code>c</code>, return <em>the</em> <strong><em>maximum</em> </strong><em><strong>score</strong> you can get.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 2, b = 4, c = 6\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The starting state is (2, 4, 6). One optimal set of moves is:\n- Take from 1st and 3rd piles, state is now (1, 4, 5)\n- Take from 1st and 3rd piles, state is now (0, 4, 4)\n- Take from 2nd and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 6 points.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 4, b = 4, c = 6\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> The starting state is (4, 4, 6). One optimal set of moves is:\n- Take from 1st and 2nd piles, state is now (3, 3, 6)\n- Take from 1st and 3rd piles, state is now (2, 3, 5)\n- Take from 1st and 3rd piles, state is now (1, 3, 4)\n- Take from 1st and 3rd piles, state is now (0, 3, 3)\n- Take from 2nd and 3rd piles, state is now (0, 2, 2)\n- Take from 2nd and 3rd piles, state is now (0, 1, 1)\n- Take from 2nd and 3rd piles, state is now (0, 0, 0)\nThere are fewer than two non-empty piles, so the game ends. Total: 7 points.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 1, b = 8, c = 8\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> One optimal set of moves is to take from the 2nd and 3rd piles for 8 turns until they are empty.\nAfter that, there are fewer than two non-empty piles, so the game ends.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= a, b, c <= 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum Strength of a Group",
|
||||
"titleSlug": "maximum-strength-of-a-group",
|
||||
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the score of students in an exam. The teacher would like to form one <strong>non-empty</strong> group of students with maximal <strong>strength</strong>, where the strength of a group of students of indices <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, <code>i<sub>2</sub></code>, ... , <code>i<sub>k</sub></code> is defined as <code>nums[i<sub>0</sub>] * nums[i<sub>1</sub>] * nums[i<sub>2</sub>] * ... * nums[i<sub>k</sub>]</code>.</p>\n\n<p>Return <em>the maximum strength of a group the teacher can create</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,-1,-5,2,5,-9]\n<strong>Output:</strong> 1350\n<strong>Explanation:</strong> One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-4,-5,-4]\n<strong>Output:</strong> 20\n<strong>Explanation:</strong> Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 13</code></li>\n\t<li><code>-9 <= nums[i] <= 9</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the score of students in an exam. The teacher would like to form one <strong>non-empty</strong> group of students with maximal <strong>strength</strong>, where the strength of a group of students of indices <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, <code>i<sub>2</sub></code>, ... , <code>i<sub>k</sub></code> is defined as <code>nums[i<sub>0</sub>] * nums[i<sub>1</sub>] * nums[i<sub>2</sub>] * ... * nums[i<sub>k</sub>]</code>.</p>\n\n<p>Return <em>the maximum strength of a group the teacher can create</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,-1,-5,2,5,-9]\n<strong>Output:</strong> 1350\n<strong>Explanation:</strong> One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-4,-5,-4]\n<strong>Output:</strong> 20\n<strong>Explanation:</strong> Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 13</code></li>\n\t<li><code>-9 <= nums[i] <= 9</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum Value after Insertion",
|
||||
"titleSlug": "maximum-value-after-insertion",
|
||||
"content": "<p>You are given a very large integer <code>n</code>, represented as a string, and an integer digit <code>x</code>. The digits in <code>n</code> and the digit <code>x</code> are in the <strong>inclusive</strong> range <code>[1, 9]</code>, and <code>n</code> may represent a <b>negative</b> number.</p>\n\n<p>You want to <strong>maximize </strong><code>n</code><strong>'s numerical value</strong> by inserting <code>x</code> anywhere in the decimal representation of <code>n</code>. You <strong>cannot</strong> insert <code>x</code> to the left of the negative sign.</p>\n\n<ul>\n\t<li>For example, if <code>n = 73</code> and <code>x = 6</code>, it would be best to insert it between <code>7</code> and <code>3</code>, making <code>n = 763</code>.</li>\n\t<li>If <code>n = -55</code> and <code>x = 2</code>, it would be best to insert it before the first <code>5</code>, making <code>n = -255</code>.</li>\n</ul>\n\n<p>Return <em>a string representing the <strong>maximum</strong> value of </em><code>n</code><em> after the insertion</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = "99", x = 9\n<strong>Output:</strong> "999"\n<strong>Explanation:</strong> The result is the same regardless of where you insert 9.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = "-13", x = 2\n<strong>Output:</strong> "-123"\n<strong>Explanation:</strong> You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= x <= 9</code></li>\n\t<li>The digits in <code>n</code> are in the range <code>[1, 9]</code>.</li>\n\t<li><code>n</code> is a valid representation of an integer.</li>\n\t<li>In the case of a negative <code>n</code>, it will begin with <code>'-'</code>.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a very large integer <code>n</code>, represented as a string, and an integer digit <code>x</code>. The digits in <code>n</code> and the digit <code>x</code> are in the <strong>inclusive</strong> range <code>[1, 9]</code>, and <code>n</code> may represent a <b>negative</b> number.</p>\n\n<p>You want to <strong>maximize </strong><code>n</code><strong>'s numerical value</strong> by inserting <code>x</code> anywhere in the decimal representation of <code>n</code>. You <strong>cannot</strong> insert <code>x</code> to the left of the negative sign.</p>\n\n<ul>\n\t<li>For example, if <code>n = 73</code> and <code>x = 6</code>, it would be best to insert it between <code>7</code> and <code>3</code>, making <code>n = 763</code>.</li>\n\t<li>If <code>n = -55</code> and <code>x = 2</code>, it would be best to insert it before the first <code>5</code>, making <code>n = -255</code>.</li>\n</ul>\n\n<p>Return <em>a string representing the <strong>maximum</strong> value of </em><code>n</code><em> after the insertion</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = "99", x = 9\n<strong>Output:</strong> "999"\n<strong>Explanation:</strong> The result is the same regardless of where you insert 9.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = "-13", x = 2\n<strong>Output:</strong> "-123"\n<strong>Explanation:</strong> You can make n one of {-213, -123, -132}, and the largest of those three is -123.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= x <= 9</code></li>\n\t<li>The digits in <code>n</code> are in the range <code>[1, 9]</code>.</li>\n\t<li><code>n</code> is a valid representation of an integer.</li>\n\t<li>In the case of a negative <code>n</code>, it will begin with <code>'-'</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Maximum XOR for Each Query",
|
||||
"titleSlug": "maximum-xor-for-each-query",
|
||||
"content": "<p>You are given a <strong>sorted</strong> array <code>nums</code> of <code>n</code> non-negative integers and an integer <code>maximumBit</code>. You want to perform the following query <code>n</code> <strong>times</strong>:</p>\n\n<ol>\n\t<li>Find a non-negative integer <code>k < 2<sup>maximumBit</sup></code> such that <code>nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k</code> is <strong>maximized</strong>. <code>k</code> is the answer to the <code>i<sup>th</sup></code> query.</li>\n\t<li>Remove the <strong>last </strong>element from the current array <code>nums</code>.</li>\n</ol>\n\n<p>Return <em>an array</em> <code>answer</code><em>, where </em><code>answer[i]</code><em> is the answer to the </em><code>i<sup>th</sup></code><em> query</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,1,3], maximumBit = 2\n<strong>Output:</strong> [0,3,2,3]\n<strong>Explanation</strong>: The queries are answered as follows:\n1<sup>st</sup> query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2<sup>nd</sup> query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3<sup>rd</sup> query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4<sup>th</sup> query: nums = [0], k = 3 since 0 XOR 3 = 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,3,4,7], maximumBit = 3\n<strong>Output:</strong> [5,2,6,5]\n<strong>Explanation</strong>: The queries are answered as follows:\n1<sup>st</sup> query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2<sup>nd</sup> query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3<sup>rd</sup> query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4<sup>th</sup> query: nums = [2], k = 5 since 2 XOR 5 = 7.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,2,2,5,7], maximumBit = 3\n<strong>Output:</strong> [4,3,6,4,6,7]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>nums.length == n</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= maximumBit <= 20</code></li>\n\t<li><code>0 <= nums[i] < 2<sup>maximumBit</sup></code></li>\n\t<li><code>nums</code> is sorted in <strong>ascending</strong> order.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a <strong>sorted</strong> array <code>nums</code> of <code>n</code> non-negative integers and an integer <code>maximumBit</code>. You want to perform the following query <code>n</code> <strong>times</strong>:</p>\n\n<ol>\n\t<li>Find a non-negative integer <code>k < 2<sup>maximumBit</sup></code> such that <code>nums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR k</code> is <strong>maximized</strong>. <code>k</code> is the answer to the <code>i<sup>th</sup></code> query.</li>\n\t<li>Remove the <strong>last </strong>element from the current array <code>nums</code>.</li>\n</ol>\n\n<p>Return <em>an array</em> <code>answer</code><em>, where </em><code>answer[i]</code><em> is the answer to the </em><code>i<sup>th</sup></code><em> query</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,1,3], maximumBit = 2\n<strong>Output:</strong> [0,3,2,3]\n<strong>Explanation</strong>: The queries are answered as follows:\n1<sup>st</sup> query: nums = [0,1,1,3], k = 0 since 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3.\n2<sup>nd</sup> query: nums = [0,1,1], k = 3 since 0 XOR 1 XOR 1 XOR 3 = 3.\n3<sup>rd</sup> query: nums = [0,1], k = 2 since 0 XOR 1 XOR 2 = 3.\n4<sup>th</sup> query: nums = [0], k = 3 since 0 XOR 3 = 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,3,4,7], maximumBit = 3\n<strong>Output:</strong> [5,2,6,5]\n<strong>Explanation</strong>: The queries are answered as follows:\n1<sup>st</sup> query: nums = [2,3,4,7], k = 5 since 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.\n2<sup>nd</sup> query: nums = [2,3,4], k = 2 since 2 XOR 3 XOR 4 XOR 2 = 7.\n3<sup>rd</sup> query: nums = [2,3], k = 6 since 2 XOR 3 XOR 6 = 7.\n4<sup>th</sup> query: nums = [2], k = 5 since 2 XOR 5 = 7.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,2,2,5,7], maximumBit = 3\n<strong>Output:</strong> [4,3,6,4,6,7]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>nums.length == n</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= maximumBit <= 20</code></li>\n\t<li><code>0 <= nums[i] < 2<sup>maximumBit</sup></code></li>\n\t<li><code>nums</code> is sorted in <strong>ascending</strong> order.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Deletions to Make String Balanced",
|
||||
"titleSlug": "minimum-deletions-to-make-string-balanced",
|
||||
"content": "<p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>.</p>\n\n<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices <code>(i,j)</code> such that <code>i < j</code> and <code>s[i] = 'b'</code> and <code>s[j]= 'a'</code>.</p>\n\n<p>Return <em>the <strong>minimum</strong> number of deletions needed to make </em><code>s</code><em> <strong>balanced</strong></em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aababbab"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> You can either:\nDelete the characters at 0-indexed positions 2 and 6 ("aa<u>b</u>abb<u>a</u>b" -> "aaabbb"), or\nDelete the characters at 0-indexed positions 3 and 6 ("aab<u>a</u>bb<u>a</u>b" -> "aabbbb").\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "bbaaaaabb"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The only solution is to delete the first two characters.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 10<sup>5</sup></code></li>\n\t<li><code>s[i]</code> is <code>'a'</code> or <code>'b'</code>.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> consisting only of characters <code>'a'</code> and <code>'b'</code>.</p>\n\n<p>You can delete any number of characters in <code>s</code> to make <code>s</code> <strong>balanced</strong>. <code>s</code> is <strong>balanced</strong> if there is no pair of indices <code>(i,j)</code> such that <code>i < j</code> and <code>s[i] = 'b'</code> and <code>s[j]= 'a'</code>.</p>\n\n<p>Return <em>the <strong>minimum</strong> number of deletions needed to make </em><code>s</code><em> <strong>balanced</strong></em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aababbab"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> You can either:\nDelete the characters at 0-indexed positions 2 and 6 ("aa<u>b</u>abb<u>a</u>b" -> "aaabbb"), or\nDelete the characters at 0-indexed positions 3 and 6 ("aab<u>a</u>bb<u>a</u>b" -> "aabbbb").\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "bbaaaaabb"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The only solution is to delete the first two characters.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 10<sup>5</sup></code></li>\n\t<li><code>s[i]</code> is <code>'a'</code> or <code>'b'</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Incompatibility",
|
||||
"titleSlug": "minimum-incompatibility",
|
||||
"content": "<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You are asked to distribute this array into <code>k</code> subsets of <strong>equal size</strong> such that there are no two equal elements in the same subset.</p>\n\n<p>A subset's <strong>incompatibility</strong> is the difference between the maximum and minimum elements in that array.</p>\n\n<p>Return <em>the <strong>minimum possible sum of incompatibilities</strong> of the </em><code>k</code> <em>subsets after distributing the array optimally, or return </em><code>-1</code><em> if it is not possible.</em></p>\n\n<p>A subset is a group integers that appear in the array with no particular order.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,1,4], k = 2\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [6,3,8,1,3,1,2,2], k = 4\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [5,3,3,6,3,3], k = 3\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= nums.length <= 16</code></li>\n\t<li><code>nums.length</code> is divisible by <code>k</code></li>\n\t<li><code>1 <= nums[i] <= nums.length</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You are asked to distribute this array into <code>k</code> subsets of <strong>equal size</strong> such that there are no two equal elements in the same subset.</p>\n\n<p>A subset's <strong>incompatibility</strong> is the difference between the maximum and minimum elements in that array.</p>\n\n<p>Return <em>the <strong>minimum possible sum of incompatibilities</strong> of the </em><code>k</code> <em>subsets after distributing the array optimally, or return </em><code>-1</code><em> if it is not possible.</em></p>\n\n<p>A subset is a group integers that appear in the array with no particular order.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,1,4], k = 2\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The optimal distribution of subsets is [1,2] and [1,4].\nThe incompatibility is (2-1) + (4-1) = 4.\nNote that [1,1] and [2,4] would result in a smaller sum, but the first subset contains 2 equal elements.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [6,3,8,1,3,1,2,2], k = 4\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The optimal distribution of subsets is [1,2], [2,3], [6,8], and [1,3].\nThe incompatibility is (2-1) + (3-2) + (8-6) + (3-1) = 6.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [5,3,3,6,3,3], k = 3\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> It is impossible to distribute nums into 3 subsets where no two elements are equal in the same subset.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= nums.length <= 16</code></li>\n\t<li><code>nums.length</code> is divisible by <code>k</code></li>\n\t<li><code>1 <= nums[i] <= nums.length</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Initial Energy to Finish Tasks",
|
||||
"titleSlug": "minimum-initial-energy-to-finish-tasks",
|
||||
"content": "<p>You are given an array <code>tasks</code> where <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code>:</p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> is the actual amount of energy you <strong>spend to finish</strong> the <code>i<sup>th</sup></code> task.</li>\n\t<li><code>minimum<sub>i</sub></code> is the minimum amount of energy you <strong>require to begin</strong> the <code>i<sup>th</sup></code> task.</li>\n</ul>\n\n<p>For example, if the task is <code>[10, 12]</code> and your current energy is <code>11</code>, you cannot start this task. However, if your current energy is <code>13</code>, you can complete this task, and your energy will be <code>3</code> after finishing it.</p>\n\n<p>You can finish the tasks in <strong>any order</strong> you like.</p>\n\n<p>Return <em>the <strong>minimum</strong> initial amount of energy you will need</em> <em>to finish all the tasks</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[4,8]]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong>\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<strong>Output:</strong> 32\n<strong>Explanation:</strong>\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= tasks.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= actual<sub>i</sub> <= minimum<sub>i</sub> <= 10<sup>4</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an array <code>tasks</code> where <code>tasks[i] = [actual<sub>i</sub>, minimum<sub>i</sub>]</code>:</p>\n\n<ul>\n\t<li><code>actual<sub>i</sub></code> is the actual amount of energy you <strong>spend to finish</strong> the <code>i<sup>th</sup></code> task.</li>\n\t<li><code>minimum<sub>i</sub></code> is the minimum amount of energy you <strong>require to begin</strong> the <code>i<sup>th</sup></code> task.</li>\n</ul>\n\n<p>For example, if the task is <code>[10, 12]</code> and your current energy is <code>11</code>, you cannot start this task. However, if your current energy is <code>13</code>, you can complete this task, and your energy will be <code>3</code> after finishing it.</p>\n\n<p>You can finish the tasks in <strong>any order</strong> you like.</p>\n\n<p>Return <em>the <strong>minimum</strong> initial amount of energy you will need</em> <em>to finish all the tasks</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[4,8]]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong>\nStarting with 8 energy, we finish the tasks in the following order:\n - 3rd task. Now energy = 8 - 4 = 4.\n - 2nd task. Now energy = 4 - 2 = 2.\n - 1st task. Now energy = 2 - 1 = 1.\nNotice that even though we have leftover energy, starting with 7 energy does not work because we cannot do the 3rd task.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,3],[2,4],[10,11],[10,12],[8,9]]\n<strong>Output:</strong> 32\n<strong>Explanation:</strong>\nStarting with 32 energy, we finish the tasks in the following order:\n - 1st task. Now energy = 32 - 1 = 31.\n - 2nd task. Now energy = 31 - 2 = 29.\n - 3rd task. Now energy = 29 - 10 = 19.\n - 4th task. Now energy = 19 - 10 = 9.\n - 5th task. Now energy = 9 - 8 = 1.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,7],[2,8],[3,9],[4,10],[5,11],[6,12]]\n<strong>Output:</strong> 27\n<strong>Explanation:</strong>\nStarting with 27 energy, we finish the tasks in the following order:\n - 5th task. Now energy = 27 - 5 = 22.\n - 2nd task. Now energy = 22 - 2 = 20.\n - 3rd task. Now energy = 20 - 3 = 17.\n - 1st task. Now energy = 17 - 1 = 16.\n - 4th task. Now energy = 16 - 4 = 12.\n - 6th task. Now energy = 12 - 6 = 6.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= tasks.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= actual<sub>i</sub> <= minimum<sub>i</sub> <= 10<sup>4</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Number of Operations to Make String Sorted",
|
||||
"titleSlug": "minimum-number-of-operations-to-make-string-sorted",
|
||||
"content": "<p>You are given a string <code>s</code> (<strong>0-indexed</strong>). You are asked to perform the following operation on <code>s</code> until you get a sorted string:</p>\n\n<ol>\n\t<li>Find <strong>the largest index</strong> <code>i</code> such that <code>1 <= i < s.length</code> and <code>s[i] < s[i - 1]</code>.</li>\n\t<li>Find <strong>the largest index</strong> <code>j</code> such that <code>i <= j < s.length</code> and <code>s[k] < s[i - 1]</code> for all the possible values of <code>k</code> in the range <code>[i, j]</code> inclusive.</li>\n\t<li>Swap the two characters at indices <code>i - 1</code> and <code>j</code>.</li>\n\t<li>Reverse the suffix starting at index <code>i</code>.</li>\n</ol>\n\n<p>Return <em>the number of operations needed to make the string sorted.</em> Since the answer can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "cba"\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> The simulation goes as follows:\nOperation 1: i=2, j=2. Swap s[1] and s[2] to get s="cab", then reverse the suffix starting at 2. Now, s="cab".\nOperation 2: i=1, j=2. Swap s[0] and s[2] to get s="bac", then reverse the suffix starting at 1. Now, s="bca".\nOperation 3: i=2, j=2. Swap s[1] and s[2] to get s="bac", then reverse the suffix starting at 2. Now, s="bac".\nOperation 4: i=1, j=1. Swap s[0] and s[1] to get s="abc", then reverse the suffix starting at 1. Now, s="acb".\nOperation 5: i=2, j=2. Swap s[1] and s[2] to get s="abc", then reverse the suffix starting at 2. Now, s="abc".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aabaa"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The simulation goes as follows:\nOperation 1: i=3, j=4. Swap s[2] and s[4] to get s="aaaab", then reverse the substring starting at 3. Now, s="aaaba".\nOperation 2: i=4, j=4. Swap s[3] and s[4] to get s="aaaab", then reverse the substring starting at 4. Now, s="aaaab".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 3000</code></li>\n\t<li><code>s</code> consists only of lowercase English letters.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> (<strong>0-indexed</strong>). You are asked to perform the following operation on <code>s</code> until you get a sorted string:</p>\n\n<ol>\n\t<li>Find <strong>the largest index</strong> <code>i</code> such that <code>1 <= i < s.length</code> and <code>s[i] < s[i - 1]</code>.</li>\n\t<li>Find <strong>the largest index</strong> <code>j</code> such that <code>i <= j < s.length</code> and <code>s[k] < s[i - 1]</code> for all the possible values of <code>k</code> in the range <code>[i, j]</code> inclusive.</li>\n\t<li>Swap the two characters at indices <code>i - 1</code> and <code>j</code>.</li>\n\t<li>Reverse the suffix starting at index <code>i</code>.</li>\n</ol>\n\n<p>Return <em>the number of operations needed to make the string sorted.</em> Since the answer can be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "cba"\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> The simulation goes as follows:\nOperation 1: i=2, j=2. Swap s[1] and s[2] to get s="cab", then reverse the suffix starting at 2. Now, s="cab".\nOperation 2: i=1, j=2. Swap s[0] and s[2] to get s="bac", then reverse the suffix starting at 1. Now, s="bca".\nOperation 3: i=2, j=2. Swap s[1] and s[2] to get s="bac", then reverse the suffix starting at 2. Now, s="bac".\nOperation 4: i=1, j=1. Swap s[0] and s[1] to get s="abc", then reverse the suffix starting at 1. Now, s="acb".\nOperation 5: i=2, j=2. Swap s[1] and s[2] to get s="abc", then reverse the suffix starting at 2. Now, s="abc".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aabaa"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The simulation goes as follows:\nOperation 1: i=3, j=4. Swap s[2] and s[4] to get s="aaaab", then reverse the substring starting at 3. Now, s="aaaba".\nOperation 2: i=4, j=4. Swap s[3] and s[4] to get s="aaaab", then reverse the substring starting at 4. Now, s="aaaab".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 3000</code></li>\n\t<li><code>s</code> consists only of lowercase English letters.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Number of Operations to Reinitialize a Permutation",
|
||||
"titleSlug": "minimum-number-of-operations-to-reinitialize-a-permutation",
|
||||
"content": "<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>\n\n<p>In one operation, you will create a new array <code>arr</code>, and for each <code>i</code>:</p>\n\n<ul>\n\t<li>If <code>i % 2 == 0</code>, then <code>arr[i] = perm[i / 2]</code>.</li>\n\t<li>If <code>i % 2 == 1</code>, then <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code>.</li>\n</ul>\n\n<p>You will then assign <code>arr</code> to <code>perm</code>.</p>\n\n<p>Return <em>the minimum <strong>non-zero</strong> number of operations you need to perform on </em><code>perm</code><em> to return the permutation to its initial value.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> perm = [0,1] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,1]\nSo it takes only 1 operation.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> perm = [0,1,2,3] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,2,1,3]\nAfter the 2<sup>nd</sup> operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6\n<strong>Output:</strong> 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> is even.</li>\n</ul>\n",
|
||||
"content": "<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>\n\n<p>In one operation, you will create a new array <code>arr</code>, and for each <code>i</code>:</p>\n\n<ul>\n\t<li>If <code>i % 2 == 0</code>, then <code>arr[i] = perm[i / 2]</code>.</li>\n\t<li>If <code>i % 2 == 1</code>, then <code>arr[i] = perm[n / 2 + (i - 1) / 2]</code>.</li>\n</ul>\n\n<p>You will then assign <code>arr</code> to <code>perm</code>.</p>\n\n<p>Return <em>the minimum <strong>non-zero</strong> number of operations you need to perform on </em><code>perm</code><em> to return the permutation to its initial value.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> perm = [0,1] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,1]\nSo it takes only 1 operation.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> perm = [0,1,2,3] initially.\nAfter the 1<sup>st</sup> operation, perm = [0,2,1,3]\nAfter the 2<sup>nd</sup> operation, perm = [0,1,2,3]\nSo it takes only 2 operations.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6\n<strong>Output:</strong> 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>n</code> is even.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Number of People to Teach",
|
||||
"titleSlug": "minimum-number-of-people-to-teach",
|
||||
"content": "<p>On a social network consisting of <code>m</code> users and some friendships between users, two users can communicate with each other if they know a common language.</p>\n\n<p>You are given an integer <code>n</code>, an array <code>languages</code>, and an array <code>friendships</code> where:</p>\n\n<ul>\n\t<li>There are <code>n</code> languages numbered <code>1</code> through <code>n</code>,</li>\n\t<li><code>languages[i]</code> is the set of languages the <code>i<sup>th</sup></code> user knows, and</li>\n\t<li><code>friendships[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes a friendship between the users <code>u<sup></sup><sub>i</sub></code> and <code>v<sub>i</sub></code>.</li>\n</ul>\n\n<p>You can choose <strong>one</strong> language and teach it to some users so that all friends can communicate with each other. Return <i data-stringify-type=\"italic\">the</i> <i><strong>minimum</strong> </i><i data-stringify-type=\"italic\">number of users you need to teach.</i></p>\nNote that friendships are not transitive, meaning if <code>x</code> is a friend of <code>y</code> and <code>y</code> is a friend of <code>z</code>, this doesn't guarantee that <code>x</code> is a friend of <code>z</code>.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> You can either teach user 1 the second language or user 2 the first language.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Teach the third language to users 1 and 3, yielding two users to teach.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 500</code></li>\n\t<li><code>languages.length == m</code></li>\n\t<li><code>1 <= m <= 500</code></li>\n\t<li><code>1 <= languages[i].length <= n</code></li>\n\t<li><code>1 <= languages[i][j] <= n</code></li>\n\t<li><code>1 <= u<sub>i</sub> < v<sub>i</sub> <= languages.length</code></li>\n\t<li><code>1 <= friendships.length <= 500</code></li>\n\t<li>All tuples <code>(u<sub>i, </sub>v<sub>i</sub>)</code> are unique</li>\n\t<li><code>languages[i]</code> contains only unique values</li>\n</ul>\n",
|
||||
"content": "<p>On a social network consisting of <code>m</code> users and some friendships between users, two users can communicate with each other if they know a common language.</p>\n\n<p>You are given an integer <code>n</code>, an array <code>languages</code>, and an array <code>friendships</code> where:</p>\n\n<ul>\n\t<li>There are <code>n</code> languages numbered <code>1</code> through <code>n</code>,</li>\n\t<li><code>languages[i]</code> is the set of languages the <code>i<sup>th</sup></code> user knows, and</li>\n\t<li><code>friendships[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes a friendship between the users <code>u<sup></sup><sub>i</sub></code> and <code>v<sub>i</sub></code>.</li>\n</ul>\n\n<p>You can choose <strong>one</strong> language and teach it to some users so that all friends can communicate with each other. Return <i data-stringify-type=\"italic\">the</i> <i><strong>minimum</strong> </i><i data-stringify-type=\"italic\">number of users you need to teach.</i></p>\nNote that friendships are not transitive, meaning if <code>x</code> is a friend of <code>y</code> and <code>y</code> is a friend of <code>z</code>, this doesn't guarantee that <code>x</code> is a friend of <code>z</code>.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> You can either teach user 1 the second language or user 2 the first language.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Teach the third language to users 1 and 3, yielding two users to teach.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 500</code></li>\n\t<li><code>languages.length == m</code></li>\n\t<li><code>1 <= m <= 500</code></li>\n\t<li><code>1 <= languages[i].length <= n</code></li>\n\t<li><code>1 <= languages[i][j] <= n</code></li>\n\t<li><code>1 <= u<sub>i</sub> < v<sub>i</sub> <= languages.length</code></li>\n\t<li><code>1 <= friendships.length <= 500</code></li>\n\t<li>All tuples <code>(u<sub>i, </sub>v<sub>i</sub>)</code> are unique</li>\n\t<li><code>languages[i]</code> contains only unique values</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Number of Removals to Make Mountain Array",
|
||||
"titleSlug": "minimum-number-of-removals-to-make-mountain-array",
|
||||
"content": "<p>You may recall that an array <code>arr</code> is a <strong>mountain array</strong> if and only if:</p>\n\n<ul>\n\t<li><code>arr.length >= 3</code></li>\n\t<li>There exists some index <code>i</code> (<strong>0-indexed</strong>) with <code>0 < i < arr.length - 1</code> such that:\n\t<ul>\n\t\t<li><code>arr[0] < arr[1] < ... < arr[i - 1] < arr[i]</code></li>\n\t\t<li><code>arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code></li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>Given an integer array <code>nums</code>, return <em>the <strong>minimum</strong> number of elements to remove to make </em><code>nums<em></em></code><em> </em><em>a <strong>mountain array</strong>.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,1]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The array itself is a mountain array so we do not need to remove any elements.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,1,1,5,6,2,3,1]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= nums.length <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li>It is guaranteed that you can make a mountain array out of <code>nums</code>.</li>\n</ul>\n",
|
||||
"content": "<p>You may recall that an array <code>arr</code> is a <strong>mountain array</strong> if and only if:</p>\n\n<ul>\n\t<li><code>arr.length >= 3</code></li>\n\t<li>There exists some index <code>i</code> (<strong>0-indexed</strong>) with <code>0 < i < arr.length - 1</code> such that:\n\t<ul>\n\t\t<li><code>arr[0] < arr[1] < ... < arr[i - 1] < arr[i]</code></li>\n\t\t<li><code>arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code></li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>Given an integer array <code>nums</code>, return <em>the <strong>minimum</strong> number of elements to remove to make </em><code>nums<em></em></code><em> </em><em>a <strong>mountain array</strong>.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,1]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The array itself is a mountain array so we do not need to remove any elements.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,1,1,5,6,2,3,1]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> One solution is to remove the elements at indices 0, 1, and 5, making the array nums = [1,5,6,3,1].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= nums.length <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n\t<li>It is guaranteed that you can make a mountain array out of <code>nums</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Minimum Time to Repair Cars",
|
||||
"titleSlug": "minimum-time-to-repair-cars",
|
||||
"content": "<p>You are given an integer array <code>ranks</code> representing the <strong>ranks</strong> of some mechanics. <font face=\"monospace\">ranks<sub>i</sub></font> is the rank of the <font face=\"monospace\">i<sup>th</sup></font> mechanic<font face=\"monospace\">.</font> A mechanic with a rank <code>r</code> can repair <font face=\"monospace\">n</font> cars in <code>r * n<sup>2</sup></code> minutes.</p>\n\n<p>You are also given an integer <code>cars</code> representing the total number of cars waiting in the garage to be repaired.</p>\n\n<p>Return <em>the <strong>minimum</strong> time taken to repair all the cars.</em></p>\n\n<p><strong>Note:</strong> All the mechanics can repair the cars simultaneously.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> ranks = [4,2,3,1], cars = 10\n<strong>Output:</strong> 16\n<strong>Explanation:</strong> \n- The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.\n- The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.\n- The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.\n- The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> ranks = [5,1,8], cars = 6\n<strong>Output:</strong> 16\n<strong>Explanation:</strong> \n- The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.\n- The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n- The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= ranks.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= ranks[i] <= 100</code></li>\n\t<li><code>1 <= cars <= 10<sup>6</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an integer array <code>ranks</code> representing the <strong>ranks</strong> of some mechanics. <font face=\"monospace\">ranks<sub>i</sub></font> is the rank of the <font face=\"monospace\">i<sup>th</sup></font> mechanic<font face=\"monospace\">.</font> A mechanic with a rank <code>r</code> can repair <font face=\"monospace\">n</font> cars in <code>r * n<sup>2</sup></code> minutes.</p>\n\n<p>You are also given an integer <code>cars</code> representing the total number of cars waiting in the garage to be repaired.</p>\n\n<p>Return <em>the <strong>minimum</strong> time taken to repair all the cars.</em></p>\n\n<p><strong>Note:</strong> All the mechanics can repair the cars simultaneously.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> ranks = [4,2,3,1], cars = 10\n<strong>Output:</strong> 16\n<strong>Explanation:</strong> \n- The first mechanic will repair two cars. The time required is 4 * 2 * 2 = 16 minutes.\n- The second mechanic will repair two cars. The time required is 2 * 2 * 2 = 8 minutes.\n- The third mechanic will repair two cars. The time required is 3 * 2 * 2 = 12 minutes.\n- The fourth mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> ranks = [5,1,8], cars = 6\n<strong>Output:</strong> 16\n<strong>Explanation:</strong> \n- The first mechanic will repair one car. The time required is 5 * 1 * 1 = 5 minutes.\n- The second mechanic will repair four cars. The time required is 1 * 4 * 4 = 16 minutes.\n- The third mechanic will repair one car. The time required is 8 * 1 * 1 = 8 minutes.\nIt can be proved that the cars cannot be repaired in less than 16 minutes.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= ranks.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= ranks[i] <= 100</code></li>\n\t<li><code>1 <= cars <= 10<sup>6</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Number of Students Unable to Eat Lunch",
|
||||
"titleSlug": "number-of-students-unable-to-eat-lunch",
|
||||
"content": "<p>The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers <code>0</code> and <code>1</code> respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.</p>\n\n<p>The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a <strong>stack</strong>. At each step:</p>\n\n<ul>\n\t<li>If the student at the front of the queue <strong>prefers</strong> the sandwich on the top of the stack, they will <strong>take it</strong> and leave the queue.</li>\n\t<li>Otherwise, they will <strong>leave it</strong> and go to the queue's end.</li>\n</ul>\n\n<p>This continues until none of the queue students want to take the top sandwich and are thus unable to eat.</p>\n\n<p>You are given two integer arrays <code>students</code> and <code>sandwiches</code> where <code>sandwiches[i]</code> is the type of the <code>i<sup>th</sup></code> sandwich in the stack (<code>i = 0</code> is the top of the stack) and <code>students[j]</code> is the preference of the <code>j<sup>th</sup></code> student in the initial queue (<code>j = 0</code> is the front of the queue). Return <em>the number of students that are unable to eat.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> students = [1,1,0,0], sandwiches = [0,1,0,1]\n<strong>Output:</strong> 0<strong> \nExplanation:</strong>\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\n<strong>Output:</strong> 3\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= students.length, sandwiches.length <= 100</code></li>\n\t<li><code>students.length == sandwiches.length</code></li>\n\t<li><code>sandwiches[i]</code> is <code>0</code> or <code>1</code>.</li>\n\t<li><code>students[i]</code> is <code>0</code> or <code>1</code>.</li>\n</ul>\n",
|
||||
"content": "<p>The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers <code>0</code> and <code>1</code> respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.</p>\n\n<p>The number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are placed in a <strong>stack</strong>. At each step:</p>\n\n<ul>\n\t<li>If the student at the front of the queue <strong>prefers</strong> the sandwich on the top of the stack, they will <strong>take it</strong> and leave the queue.</li>\n\t<li>Otherwise, they will <strong>leave it</strong> and go to the queue's end.</li>\n</ul>\n\n<p>This continues until none of the queue students want to take the top sandwich and are thus unable to eat.</p>\n\n<p>You are given two integer arrays <code>students</code> and <code>sandwiches</code> where <code>sandwiches[i]</code> is the type of the <code>i<sup>th</sup></code> sandwich in the stack (<code>i = 0</code> is the top of the stack) and <code>students[j]</code> is the preference of the <code>j<sup>th</sup></code> student in the initial queue (<code>j = 0</code> is the front of the queue). Return <em>the number of students that are unable to eat.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> students = [1,1,0,0], sandwiches = [0,1,0,1]\n<strong>Output:</strong> 0<strong> \nExplanation:</strong>\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,0,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,0,1,1].\n- Front student takes the top sandwich and leaves the line making students = [0,1,1] and sandwiches = [1,0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [1,1,0].\n- Front student takes the top sandwich and leaves the line making students = [1,0] and sandwiches = [0,1].\n- Front student leaves the top sandwich and returns to the end of the line making students = [0,1].\n- Front student takes the top sandwich and leaves the line making students = [1] and sandwiches = [1].\n- Front student takes the top sandwich and leaves the line making students = [] and sandwiches = [].\nHence all students are able to eat.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]\n<strong>Output:</strong> 3\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= students.length, sandwiches.length <= 100</code></li>\n\t<li><code>students.length == sandwiches.length</code></li>\n\t<li><code>sandwiches[i]</code> is <code>0</code> or <code>1</code>.</li>\n\t<li><code>students[i]</code> is <code>0</code> or <code>1</code>.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Number of Valid Move Combinations On Chessboard",
|
||||
"titleSlug": "number-of-valid-move-combinations-on-chessboard",
|
||||
"content": "<p>There is an <code>8 x 8</code> chessboard containing <code>n</code> pieces (rooks, queens, or bishops). You are given a string array <code>pieces</code> of length <code>n</code>, where <code>pieces[i]</code> describes the type (rook, queen, or bishop) of the <code>i<sup>th</sup></code> piece. In addition, you are given a 2D integer array <code>positions</code> also of length <code>n</code>, where <code>positions[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> indicates that the <code>i<sup>th</sup></code> piece is currently at the <strong>1-based</strong> coordinate <code>(r<sub>i</sub>, c<sub>i</sub>)</code> on the chessboard.</p>\n\n<p>When making a <strong>move</strong> for a piece, you choose a <strong>destination</strong> square that the piece will travel toward and stop on.</p>\n\n<ul>\n\t<li>A rook can only travel <strong>horizontally or vertically</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c)</code>, <code>(r-1, c)</code>, <code>(r, c+1)</code>, or <code>(r, c-1)</code>.</li>\n\t<li>A queen can only travel <strong>horizontally, vertically, or diagonally</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c)</code>, <code>(r-1, c)</code>, <code>(r, c+1)</code>, <code>(r, c-1)</code>, <code>(r+1, c+1)</code>, <code>(r+1, c-1)</code>, <code>(r-1, c+1)</code>, <code>(r-1, c-1)</code>.</li>\n\t<li>A bishop can only travel <strong>diagonally</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c+1)</code>, <code>(r+1, c-1)</code>, <code>(r-1, c+1)</code>, <code>(r-1, c-1)</code>.</li>\n</ul>\n\n<p>You must make a <strong>move</strong> for every piece on the board simultaneously. A <strong>move combination</strong> consists of all the <strong>moves</strong> performed on all the given pieces. Every second, each piece will instantaneously travel <strong>one square</strong> towards their destination if they are not already at it. All pieces start traveling at the <code>0<sup>th</sup></code> second. A move combination is <strong>invalid</strong> if, at a given time, <strong>two or more</strong> pieces occupy the same square.</p>\n\n<p>Return <em>the number of <strong>valid</strong> move combinations</em>.</p>\n\n<p><strong>Notes:</strong></p>\n\n<ul>\n\t<li><strong>No two pieces</strong> will start in the<strong> same</strong> square.</li>\n\t<li>You may choose the square a piece is already on as its <strong>destination</strong>.</li>\n\t<li>If two pieces are <strong>directly adjacent</strong> to each other, it is valid for them to <strong>move past each other</strong> and swap positions in one second.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a1.png\" style=\"width: 215px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["rook"], positions = [[1,1]]\n<strong>Output:</strong> 15\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a2.png\" style=\"width: 215px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["queen"], positions = [[1,1]]\n<strong>Output:</strong> 22\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a3.png\" style=\"width: 214px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["bishop"], positions = [[4,3]]\n<strong>Output:</strong> 12\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == pieces.length </code></li>\n\t<li><code>n == positions.length</code></li>\n\t<li><code>1 <= n <= 4</code></li>\n\t<li><code>pieces</code> only contains the strings <code>"rook"</code>, <code>"queen"</code>, and <code>"bishop"</code>.</li>\n\t<li>There will be at most one queen on the chessboard.</li>\n\t<li><code>1 <= x<sub>i</sub>, y<sub>i</sub> <= 8</code></li>\n\t<li>Each <code>positions[i]</code> is distinct.</li>\n</ul>\n",
|
||||
"content": "<p>There is an <code>8 x 8</code> chessboard containing <code>n</code> pieces (rooks, queens, or bishops). You are given a string array <code>pieces</code> of length <code>n</code>, where <code>pieces[i]</code> describes the type (rook, queen, or bishop) of the <code>i<sup>th</sup></code> piece. In addition, you are given a 2D integer array <code>positions</code> also of length <code>n</code>, where <code>positions[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> indicates that the <code>i<sup>th</sup></code> piece is currently at the <strong>1-based</strong> coordinate <code>(r<sub>i</sub>, c<sub>i</sub>)</code> on the chessboard.</p>\n\n<p>When making a <strong>move</strong> for a piece, you choose a <strong>destination</strong> square that the piece will travel toward and stop on.</p>\n\n<ul>\n\t<li>A rook can only travel <strong>horizontally or vertically</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c)</code>, <code>(r-1, c)</code>, <code>(r, c+1)</code>, or <code>(r, c-1)</code>.</li>\n\t<li>A queen can only travel <strong>horizontally, vertically, or diagonally</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c)</code>, <code>(r-1, c)</code>, <code>(r, c+1)</code>, <code>(r, c-1)</code>, <code>(r+1, c+1)</code>, <code>(r+1, c-1)</code>, <code>(r-1, c+1)</code>, <code>(r-1, c-1)</code>.</li>\n\t<li>A bishop can only travel <strong>diagonally</strong> from <code>(r, c)</code> to the direction of <code>(r+1, c+1)</code>, <code>(r+1, c-1)</code>, <code>(r-1, c+1)</code>, <code>(r-1, c-1)</code>.</li>\n</ul>\n\n<p>You must make a <strong>move</strong> for every piece on the board simultaneously. A <strong>move combination</strong> consists of all the <strong>moves</strong> performed on all the given pieces. Every second, each piece will instantaneously travel <strong>one square</strong> towards their destination if they are not already at it. All pieces start traveling at the <code>0<sup>th</sup></code> second. A move combination is <strong>invalid</strong> if, at a given time, <strong>two or more</strong> pieces occupy the same square.</p>\n\n<p>Return <em>the number of <strong>valid</strong> move combinations</em>.</p>\n\n<p><strong>Notes:</strong></p>\n\n<ul>\n\t<li><strong>No two pieces</strong> will start in the<strong> same</strong> square.</li>\n\t<li>You may choose the square a piece is already on as its <strong>destination</strong>.</li>\n\t<li>If two pieces are <strong>directly adjacent</strong> to each other, it is valid for them to <strong>move past each other</strong> and swap positions in one second.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a1.png\" style=\"width: 215px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["rook"], positions = [[1,1]]\n<strong>Output:</strong> 15\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a2.png\" style=\"width: 215px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["queen"], positions = [[1,1]]\n<strong>Output:</strong> 22\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/09/23/a3.png\" style=\"width: 214px; height: 215px;\" />\n<pre>\n<strong>Input:</strong> pieces = ["bishop"], positions = [[4,3]]\n<strong>Output:</strong> 12\n<strong>Explanation:</strong> The image above shows the possible squares the piece can move to.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == pieces.length </code></li>\n\t<li><code>n == positions.length</code></li>\n\t<li><code>1 <= n <= 4</code></li>\n\t<li><code>pieces</code> only contains the strings <code>"rook"</code>, <code>"queen"</code>, and <code>"bishop"</code>.</li>\n\t<li>There will be at most one queen on the chessboard.</li>\n\t<li><code>1 <= x<sub>i</sub>, y<sub>i</sub> <= 8</code></li>\n\t<li>Each <code>positions[i]</code> is distinct.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Palindrome Partitioning IV",
|
||||
"titleSlug": "palindrome-partitioning-iv",
|
||||
"content": "<p>Given a string <code>s</code>, return <code>true</code> <em>if it is possible to split the string</em> <code>s</code> <em>into three <strong>non-empty</strong> palindromic substrings. Otherwise, return </em><code>false</code>.</p>\n\n<p>A string is said to be palindrome if it the same string when reversed.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "abcbdd"\n<strong>Output:</strong> true\n<strong>Explanation: </strong>"abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "bcbddxy"\n<strong>Output:</strong> false\n<strong>Explanation: </strong>s cannot be split into 3 palindromes.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= s.length <= 2000</code></li>\n\t<li><code>s</code> consists only of lowercase English letters.</li>\n</ul>\n",
|
||||
"content": "<p>Given a string <code>s</code>, return <code>true</code> <em>if it is possible to split the string</em> <code>s</code> <em>into three <strong>non-empty</strong> palindromic substrings. Otherwise, return </em><code>false</code>.</p>\n\n<p>A string is said to be palindrome if it the same string when reversed.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "abcbdd"\n<strong>Output:</strong> true\n<strong>Explanation: </strong>"abcbdd" = "a" + "bcb" + "dd", and all three substrings are palindromes.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "bcbddxy"\n<strong>Output:</strong> false\n<strong>Explanation: </strong>s cannot be split into 3 palindromes.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= s.length <= 2000</code></li>\n\t<li><code>s</code> consists only of lowercase English letters.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Power of Heroes",
|
||||
"titleSlug": "power-of-heroes",
|
||||
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the strength of some heroes. The<b> power</b> of a group of heroes is defined as follows:</p>\n\n<ul>\n\t<li>Let <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, ... ,<code>i<sub>k</sub></code> be the indices of the heroes in a group. Then, the power of this group is <code>max(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])<sup>2</sup> * min(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])</code>.</li>\n</ul>\n\n<p>Return <em>the sum of the <strong>power</strong> of all <strong>non-empty</strong> groups of heroes possible.</em> Since the sum could be very large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,1,4]\n<strong>Output:</strong> 141\n<strong>Explanation:</strong> \n1<sup>st</sup> group: [2] has power = 2<sup>2</sup> * 2 = 8.\n2<sup>nd</sup> group: [1] has power = 1<sup>2</sup> * 1 = 1. \n3<sup>rd</sup> group: [4] has power = 4<sup>2</sup> * 4 = 64. \n4<sup>th</sup> group: [2,1] has power = 2<sup>2</sup> * 1 = 4. \n5<sup>th</sup> group: [2,4] has power = 4<sup>2</sup> * 2 = 32. \n6<sup>th</sup> group: [1,4] has power = 4<sup>2</sup> * 1 = 16. \n7<sup>th</sup> group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16. \nThe sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.\n\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,1,1]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the strength of some heroes. The<b> power</b> of a group of heroes is defined as follows:</p>\n\n<ul>\n\t<li>Let <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, ... ,<code>i<sub>k</sub></code> be the indices of the heroes in a group. Then, the power of this group is <code>max(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])<sup>2</sup> * min(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])</code>.</li>\n</ul>\n\n<p>Return <em>the sum of the <strong>power</strong> of all <strong>non-empty</strong> groups of heroes possible.</em> Since the sum could be very large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,1,4]\n<strong>Output:</strong> 141\n<strong>Explanation:</strong> \n1<sup>st</sup> group: [2] has power = 2<sup>2</sup> * 2 = 8.\n2<sup>nd</sup> group: [1] has power = 1<sup>2</sup> * 1 = 1. \n3<sup>rd</sup> group: [4] has power = 4<sup>2</sup> * 4 = 64. \n4<sup>th</sup> group: [2,1] has power = 2<sup>2</sup> * 1 = 4. \n5<sup>th</sup> group: [2,4] has power = 4<sup>2</sup> * 2 = 32. \n6<sup>th</sup> group: [1,4] has power = 4<sup>2</sup> * 1 = 16. \n7<sup>th</sup> group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16. \nThe sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.\n\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,1,1]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Process Tasks Using Servers",
|
||||
"titleSlug": "process-tasks-using-servers",
|
||||
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>\n\n<p>Tasks are assigned to the servers using a <strong>task queue</strong>. Initially, all servers are free, and the queue is <strong>empty</strong>.</p>\n\n<p>At second <code>j</code>, the <code>j<sup>th</sup></code> task is <strong>inserted</strong> into the queue (starting with the <code>0<sup>th</sup></code> task being inserted at second <code>0</code>). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the <strong>smallest weight</strong>, and in case of a tie, it is assigned to a free server with the <strong>smallest index</strong>.</p>\n\n<p>If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned <strong>in order of insertion</strong> following the weight and index priorities above.</p>\n\n<p>A server that is assigned task <code>j</code> at second <code>t</code> will be free again at second <code>t + tasks[j]</code>.</p>\n\n<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>\n\n<p>Return <em>the array </em><code>ans</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>Output:</strong> [2,2,0,2,1,2]\n<strong>Explanation: </strong>Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>Output:</strong> [1,4,1,4,1,3,2]\n<strong>Explanation: </strong>Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>servers</code> and <code>tasks</code> of lengths <code>n</code> and <code>m</code> respectively. <code>servers[i]</code> is the <strong>weight</strong> of the <code>i<sup>th</sup></code> server, and <code>tasks[j]</code> is the <strong>time needed</strong> to process the <code>j<sup>th</sup></code> task <strong>in seconds</strong>.</p>\n\n<p>Tasks are assigned to the servers using a <strong>task queue</strong>. Initially, all servers are free, and the queue is <strong>empty</strong>.</p>\n\n<p>At second <code>j</code>, the <code>j<sup>th</sup></code> task is <strong>inserted</strong> into the queue (starting with the <code>0<sup>th</sup></code> task being inserted at second <code>0</code>). As long as there are free servers and the queue is not empty, the task in the front of the queue will be assigned to a free server with the <strong>smallest weight</strong>, and in case of a tie, it is assigned to a free server with the <strong>smallest index</strong>.</p>\n\n<p>If there are no free servers and the queue is not empty, we wait until a server becomes free and immediately assign the next task. If multiple servers become free at the same time, then multiple tasks from the queue will be assigned <strong>in order of insertion</strong> following the weight and index priorities above.</p>\n\n<p>A server that is assigned task <code>j</code> at second <code>t</code> will be free again at second <code>t + tasks[j]</code>.</p>\n\n<p>Build an array <code>ans</code> of length <code>m</code>, where <code>ans[j]</code> is the <strong>index</strong> of the server the <code>j<sup>th</sup></code> task will be assigned to.</p>\n\n<p>Return <em>the array </em><code>ans</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [3,3,2], tasks = [1,2,3,2,1,2]\n<strong>Output:</strong> [2,2,0,2,1,2]\n<strong>Explanation: </strong>Events in chronological order go as follows:\n- At second 0, task 0 is added and processed using server 2 until second 1.\n- At second 1, server 2 becomes free. Task 1 is added and processed using server 2 until second 3.\n- At second 2, task 2 is added and processed using server 0 until second 5.\n- At second 3, server 2 becomes free. Task 3 is added and processed using server 2 until second 5.\n- At second 4, task 4 is added and processed using server 1 until second 5.\n- At second 5, all servers become free. Task 5 is added and processed using server 2 until second 7.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> servers = [5,1,4,3,2], tasks = [2,1,2,4,5,2,1]\n<strong>Output:</strong> [1,4,1,4,1,3,2]\n<strong>Explanation: </strong>Events in chronological order go as follows: \n- At second 0, task 0 is added and processed using server 1 until second 2.\n- At second 1, task 1 is added and processed using server 4 until second 2.\n- At second 2, servers 1 and 4 become free. Task 2 is added and processed using server 1 until second 4. \n- At second 3, task 3 is added and processed using server 4 until second 7.\n- At second 4, server 1 becomes free. Task 4 is added and processed using server 1 until second 9. \n- At second 5, task 5 is added and processed using server 3 until second 7.\n- At second 6, task 6 is added and processed using server 2 until second 7.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>servers.length == n</code></li>\n\t<li><code>tasks.length == m</code></li>\n\t<li><code>1 <= n, m <= 2 * 10<sup>5</sup></code></li>\n\t<li><code>1 <= servers[i], tasks[j] <= 2 * 10<sup>5</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Promise Time Limit",
|
||||
"titleSlug": "promise-time-limit",
|
||||
"content": "<p>Given an asynchronous function <code>fn</code> and a time <code>t</code> in milliseconds, return a new <strong>time limited</strong> version of the input function. <code>fn</code> takes arguments provided to the <strong>time limited </strong>function.</p>\n\n<p>The <strong>time limited</strong> function should follow these rules:</p>\n\n<ul>\n\t<li>If the <code>fn</code> completes within the time limit of <code>t</code> milliseconds, the <strong>time limited</strong> function should resolve with the result.</li>\n\t<li>If the execution of the <code>fn</code> exceeds the time limit, the <strong>time limited</strong> function should reject with the string <code>"Time Limit Exceeded"</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (n) => { \n await new Promise(res => setTimeout(res, 100)); \n return n * n; \n}\ninputs = [5]\nt = 50\n<strong>Output:</strong> {"rejected":"Time Limit Exceeded","time":50}\n<strong>Explanation:</strong>\nconst limited = timeLimit(fn, t)\nconst start = performance.now()\nlet result;\ntry {\n const res = await limited(...inputs)\n result = {"resolved": res, "time": Math.floor(performance.now() - start)};\n} catch (err) {\n result = {"rejected": err, "time": Math.floor(performance.now() - start)};\n}\nconsole.log(result) // Output\n\nThe provided function is set to resolve after 100ms. However, the time limit is set to 50ms. It rejects at t=50ms because the time limit was reached.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (n) => { \n await new Promise(res => setTimeout(res, 100)); \n return n * n; \n}\ninputs = [5]\nt = 150\n<strong>Output:</strong> {"resolved":25,"time":100}\n<strong>Explanation:</strong>\nThe function resolved 5 * 5 = 25 at t=100ms. The time limit is never reached.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (a, b) => { \n await new Promise(res => setTimeout(res, 120)); \n return a + b; \n}\ninputs = [5,10]\nt = 150\n<strong>Output:</strong> {"resolved":15,"time":120}\n<strong>Explanation:</strong>\nThe function resolved 5 + 10 = 15 at t=120ms. The time limit is never reached.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async () => { \n throw "Error";\n}\ninputs = []\nt = 1000\n<strong>Output:</strong> {"rejected":"Error","time":0}\n<strong>Explanation:</strong>\nThe function immediately throws an error.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= inputs.length <= 10</code></li>\n\t<li><code>0 <= t <= 1000</code></li>\n\t<li><code>fn</code> returns a promise</li>\n</ul>\n",
|
||||
"content": "<p>Given an asynchronous function <code>fn</code> and a time <code>t</code> in milliseconds, return a new <strong>time limited</strong> version of the input function. <code>fn</code> takes arguments provided to the <strong>time limited </strong>function.</p>\n\n<p>The <strong>time limited</strong> function should follow these rules:</p>\n\n<ul>\n\t<li>If the <code>fn</code> completes within the time limit of <code>t</code> milliseconds, the <strong>time limited</strong> function should resolve with the result.</li>\n\t<li>If the execution of the <code>fn</code> exceeds the time limit, the <strong>time limited</strong> function should reject with the string <code>"Time Limit Exceeded"</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (n) => { \n await new Promise(res => setTimeout(res, 100)); \n return n * n; \n}\ninputs = [5]\nt = 50\n<strong>Output:</strong> {"rejected":"Time Limit Exceeded","time":50}\n<strong>Explanation:</strong>\nconst limited = timeLimit(fn, t)\nconst start = performance.now()\nlet result;\ntry {\n const res = await limited(...inputs)\n result = {"resolved": res, "time": Math.floor(performance.now() - start)};\n} catch (err) {\n result = {"rejected": err, "time": Math.floor(performance.now() - start)};\n}\nconsole.log(result) // Output\n\nThe provided function is set to resolve after 100ms. However, the time limit is set to 50ms. It rejects at t=50ms because the time limit was reached.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (n) => { \n await new Promise(res => setTimeout(res, 100)); \n return n * n; \n}\ninputs = [5]\nt = 150\n<strong>Output:</strong> {"resolved":25,"time":100}\n<strong>Explanation:</strong>\nThe function resolved 5 * 5 = 25 at t=100ms. The time limit is never reached.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async (a, b) => { \n await new Promise(res => setTimeout(res, 120)); \n return a + b; \n}\ninputs = [5,10]\nt = 150\n<strong>Output:</strong> {"resolved":15,"time":120}\n<strong>Explanation:</strong>\nThe function resolved 5 + 10 = 15 at t=120ms. The time limit is never reached.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nfn = async () => { \n throw "Error";\n}\ninputs = []\nt = 1000\n<strong>Output:</strong> {"rejected":"Error","time":0}\n<strong>Explanation:</strong>\nThe function immediately throws an error.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= inputs.length <= 10</code></li>\n\t<li><code>0 <= t <= 1000</code></li>\n\t<li><code>fn</code> returns a promise</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Queries on Number of Points Inside a Circle",
|
||||
"titleSlug": "queries-on-number-of-points-inside-a-circle",
|
||||
"content": "<p>You are given an array <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> is the coordinates of the <code>i<sup>th</sup></code> point on a 2D plane. Multiple points can have the <strong>same</strong> coordinates.</p>\n\n<p>You are also given an array <code>queries</code> where <code>queries[j] = [x<sub>j</sub>, y<sub>j</sub>, r<sub>j</sub>]</code> describes a circle centered at <code>(x<sub>j</sub>, y<sub>j</sub>)</code> with a radius of <code>r<sub>j</sub></code>.</p>\n\n<p>For each query <code>queries[j]</code>, compute the number of points <strong>inside</strong> the <code>j<sup>th</sup></code> circle. Points <strong>on the border</strong> of the circle are considered <strong>inside</strong>.</p>\n\n<p>Return <em>an array </em><code>answer</code><em>, where </em><code>answer[j]</code><em> is the answer to the </em><code>j<sup>th</sup></code><em> query</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-34-16.png\" style=\"width: 500px; height: 418px;\" />\n<pre>\n<strong>Input:</strong> points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\n<strong>Output:</strong> [3,2,2]\n<b>Explanation: </b>The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-42-07.png\" style=\"width: 500px; height: 390px;\" />\n<pre>\n<strong>Input:</strong> points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\n<strong>Output:</strong> [2,3,2,4]\n<b>Explanation: </b>The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= points.length <= 500</code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 500</code></li>\n\t<li><code>1 <= queries.length <= 500</code></li>\n\t<li><code>queries[j].length == 3</code></li>\n\t<li><code>0 <= x<sub>j</sub>, y<sub>j</sub> <= 500</code></li>\n\t<li><code>1 <= r<sub>j</sub> <= 500</code></li>\n\t<li>All coordinates are integers.</li>\n</ul>\n\n<p> </p>\n<p><strong>Follow up:</strong> Could you find the answer for each query in better complexity than <code>O(n)</code>?</p>\n",
|
||||
"content": "<p>You are given an array <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> is the coordinates of the <code>i<sup>th</sup></code> point on a 2D plane. Multiple points can have the <strong>same</strong> coordinates.</p>\n\n<p>You are also given an array <code>queries</code> where <code>queries[j] = [x<sub>j</sub>, y<sub>j</sub>, r<sub>j</sub>]</code> describes a circle centered at <code>(x<sub>j</sub>, y<sub>j</sub>)</code> with a radius of <code>r<sub>j</sub></code>.</p>\n\n<p>For each query <code>queries[j]</code>, compute the number of points <strong>inside</strong> the <code>j<sup>th</sup></code> circle. Points <strong>on the border</strong> of the circle are considered <strong>inside</strong>.</p>\n\n<p>Return <em>an array </em><code>answer</code><em>, where </em><code>answer[j]</code><em> is the answer to the </em><code>j<sup>th</sup></code><em> query</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-34-16.png\" style=\"width: 500px; height: 418px;\" />\n<pre>\n<strong>Input:</strong> points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]\n<strong>Output:</strong> [3,2,2]\n<b>Explanation: </b>The points and circles are shown above.\nqueries[0] is the green circle, queries[1] is the red circle, and queries[2] is the blue circle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/25/chrome_2021-03-25_22-42-07.png\" style=\"width: 500px; height: 390px;\" />\n<pre>\n<strong>Input:</strong> points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]\n<strong>Output:</strong> [2,3,2,4]\n<b>Explanation: </b>The points and circles are shown above.\nqueries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is purple.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= points.length <= 500</code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 500</code></li>\n\t<li><code>1 <= queries.length <= 500</code></li>\n\t<li><code>queries[j].length == 3</code></li>\n\t<li><code>0 <= x<sub>j</sub>, y<sub>j</sub> <= 500</code></li>\n\t<li><code>1 <= r<sub>j</sub> <= 500</code></li>\n\t<li>All coordinates are integers.</li>\n</ul>\n\n<p> </p>\n<p><strong>Follow up:</strong> Could you find the answer for each query in better complexity than <code>O(n)</code>?</p>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Regular Expression Matching",
|
||||
"titleSlug": "regular-expression-matching",
|
||||
"content": "<p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>\n\n<ul>\n\t<li><code>'.'</code> Matches any single character.</li>\n\t<li><code>'*'</code> Matches zero or more of the preceding element.</li>\n</ul>\n\n<p>The matching should cover the <strong>entire</strong> input string (not partial).</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aa", p = "a"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> "a" does not match the entire string "aa".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aa", p = "a*"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "ab", p = ".*"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> ".*" means "zero or more (*) of any character (.)".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 20</code></li>\n\t<li><code>1 <= p.length <= 20</code></li>\n\t<li><code>s</code> contains only lowercase English letters.</li>\n\t<li><code>p</code> contains only lowercase English letters, <code>'.'</code>, and <code>'*'</code>.</li>\n\t<li>It is guaranteed for each appearance of the character <code>'*'</code>, there will be a previous valid character to match.</li>\n</ul>\n",
|
||||
"content": "<p>Given an input string <code>s</code> and a pattern <code>p</code>, implement regular expression matching with support for <code>'.'</code> and <code>'*'</code> where:</p>\n\n<ul>\n\t<li><code>'.'</code> Matches any single character.</li>\n\t<li><code>'*'</code> Matches zero or more of the preceding element.</li>\n</ul>\n\n<p>The matching should cover the <strong>entire</strong> input string (not partial).</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aa", p = "a"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> "a" does not match the entire string "aa".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aa", p = "a*"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> '*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "ab", p = ".*"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> ".*" means "zero or more (*) of any character (.)".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 20</code></li>\n\t<li><code>1 <= p.length <= 20</code></li>\n\t<li><code>s</code> contains only lowercase English letters.</li>\n\t<li><code>p</code> contains only lowercase English letters, <code>'.'</code>, and <code>'*'</code>.</li>\n\t<li>It is guaranteed for each appearance of the character <code>'*'</code>, there will be a previous valid character to match.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Remove All Occurrences of a Substring",
|
||||
"titleSlug": "remove-all-occurrences-of-a-substring",
|
||||
"content": "<p>Given two strings <code>s</code> and <code>part</code>, perform the following operation on <code>s</code> until <strong>all</strong> occurrences of the substring <code>part</code> are removed:</p>\n\n<ul>\n\t<li>Find the <strong>leftmost</strong> occurrence of the substring <code>part</code> and <strong>remove</strong> it from <code>s</code>.</li>\n</ul>\n\n<p>Return <code>s</code><em> after removing all occurrences of </em><code>part</code>.</p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "daabcbaabcbc", part = "abc"\n<strong>Output:</strong> "dab"\n<strong>Explanation</strong>: The following operations are done:\n- s = "da<strong><u>abc</u></strong>baabcbc", remove "abc" starting at index 2, so s = "dabaabcbc".\n- s = "daba<strong><u>abc</u></strong>bc", remove "abc" starting at index 4, so s = "dababc".\n- s = "dab<strong><u>abc</u></strong>", remove "abc" starting at index 3, so s = "dab".\nNow s has no occurrences of "abc".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "axxxxyyyyb", part = "xy"\n<strong>Output:</strong> "ab"\n<strong>Explanation</strong>: The following operations are done:\n- s = "axxx<strong><u>xy</u></strong>yyyb", remove "xy" starting at index 4 so s = "axxxyyyb".\n- s = "axx<strong><u>xy</u></strong>yyb", remove "xy" starting at index 3 so s = "axxyyb".\n- s = "ax<strong><u>xy</u></strong>yb", remove "xy" starting at index 2 so s = "axyb".\n- s = "a<strong><u>xy</u></strong>b", remove "xy" starting at index 1 so s = "ab".\nNow s has no occurrences of "xy".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 1000</code></li>\n\t<li><code>1 <= part.length <= 1000</code></li>\n\t<li><code>s</code> and <code>part</code> consists of lowercase English letters.</li>\n</ul>\n",
|
||||
"content": "<p>Given two strings <code>s</code> and <code>part</code>, perform the following operation on <code>s</code> until <strong>all</strong> occurrences of the substring <code>part</code> are removed:</p>\n\n<ul>\n\t<li>Find the <strong>leftmost</strong> occurrence of the substring <code>part</code> and <strong>remove</strong> it from <code>s</code>.</li>\n</ul>\n\n<p>Return <code>s</code><em> after removing all occurrences of </em><code>part</code>.</p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "daabcbaabcbc", part = "abc"\n<strong>Output:</strong> "dab"\n<strong>Explanation</strong>: The following operations are done:\n- s = "da<strong><u>abc</u></strong>baabcbc", remove "abc" starting at index 2, so s = "dabaabcbc".\n- s = "daba<strong><u>abc</u></strong>bc", remove "abc" starting at index 4, so s = "dababc".\n- s = "dab<strong><u>abc</u></strong>", remove "abc" starting at index 3, so s = "dab".\nNow s has no occurrences of "abc".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "axxxxyyyyb", part = "xy"\n<strong>Output:</strong> "ab"\n<strong>Explanation</strong>: The following operations are done:\n- s = "axxx<strong><u>xy</u></strong>yyyb", remove "xy" starting at index 4 so s = "axxxyyyb".\n- s = "axx<strong><u>xy</u></strong>yyb", remove "xy" starting at index 3 so s = "axxyyb".\n- s = "ax<strong><u>xy</u></strong>yb", remove "xy" starting at index 2 so s = "axyb".\n- s = "a<strong><u>xy</u></strong>b", remove "xy" starting at index 1 so s = "ab".\nNow s has no occurrences of "xy".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 1000</code></li>\n\t<li><code>1 <= part.length <= 1000</code></li>\n\t<li><code>s</code> and <code>part</code> consists of lowercase English letters.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Repeated String Match",
|
||||
"titleSlug": "repeated-string-match",
|
||||
"content": "<p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string </em><code>a</code><em> so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code> to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p>\n\n<p><strong>Notice:</strong> string <code>"abc"</code> repeated 0 times is <code>""</code>, repeated 1 time is <code>"abc"</code> and repeated 2 times is <code>"abcabc"</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = "abcd", b = "cdabcdab"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> We return 3 because by repeating a three times "ab<strong>cdabcdab</strong>cd", b is a substring of it.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = "a", b = "aa"\n<strong>Output:</strong> 2\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= a.length, b.length <= 10<sup>4</sup></code></li>\n\t<li><code>a</code> and <code>b</code> consist of lowercase English letters.</li>\n</ul>\n",
|
||||
"content": "<p>Given two strings <code>a</code> and <code>b</code>, return <em>the minimum number of times you should repeat string </em><code>a</code><em> so that string</em> <code>b</code> <em>is a substring of it</em>. If it is impossible for <code>b</code> to be a substring of <code>a</code> after repeating it, return <code>-1</code>.</p>\n\n<p><strong>Notice:</strong> string <code>"abc"</code> repeated 0 times is <code>""</code>, repeated 1 time is <code>"abc"</code> and repeated 2 times is <code>"abcabc"</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = "abcd", b = "cdabcdab"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> We return 3 because by repeating a three times "ab<strong>cdabcdab</strong>cd", b is a substring of it.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = "a", b = "aa"\n<strong>Output:</strong> 2\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= a.length, b.length <= 10<sup>4</sup></code></li>\n\t<li><code>a</code> and <code>b</code> consist of lowercase English letters.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Richest Customer Wealth",
|
||||
"titleSlug": "richest-customer-wealth",
|
||||
"content": "<p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i<sup>th</sup></code> customer has in the <code>j<sup>th</sup></code> bank. Return<em> the <strong>wealth</strong> that the richest customer has.</em></p>\n\n<p>A customer's <strong>wealth</strong> is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum <strong>wealth</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[1,2,3],[3,2,1]]\n<strong>Output:</strong> 6\n<strong>Explanation</strong><strong>:</strong>\n<code>1st customer has wealth = 1 + 2 + 3 = 6\n</code><code>2nd customer has wealth = 3 + 2 + 1 = 6\n</code>Both customers are considered the richest with a wealth of 6 each, so return 6.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[1,5],[7,3],[3,5]]\n<strong>Output:</strong> 10\n<strong>Explanation</strong>: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[2,8,7],[7,1,3],[1,9,5]]\n<strong>Output:</strong> 17\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == accounts.length</code></li>\n\t<li><code>n == accounts[i].length</code></li>\n\t<li><code>1 <= m, n <= 50</code></li>\n\t<li><code>1 <= accounts[i][j] <= 100</code></li>\n</ul>\n",
|
||||
"content": "<p>You are given an <code>m x n</code> integer grid <code>accounts</code> where <code>accounts[i][j]</code> is the amount of money the <code>i<sup>th</sup></code> customer has in the <code>j<sup>th</sup></code> bank. Return<em> the <strong>wealth</strong> that the richest customer has.</em></p>\n\n<p>A customer's <strong>wealth</strong> is the amount of money they have in all their bank accounts. The richest customer is the customer that has the maximum <strong>wealth</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[1,2,3],[3,2,1]]\n<strong>Output:</strong> 6\n<strong>Explanation</strong><strong>:</strong>\n<code>1st customer has wealth = 1 + 2 + 3 = 6\n</code><code>2nd customer has wealth = 3 + 2 + 1 = 6\n</code>Both customers are considered the richest with a wealth of 6 each, so return 6.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[1,5],[7,3],[3,5]]\n<strong>Output:</strong> 10\n<strong>Explanation</strong>: \n1st customer has wealth = 6\n2nd customer has wealth = 10 \n3rd customer has wealth = 8\nThe 2nd customer is the richest with a wealth of 10.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> accounts = [[2,8,7],[7,1,3],[1,9,5]]\n<strong>Output:</strong> 17\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == accounts.length</code></li>\n\t<li><code>n == accounts[i].length</code></li>\n\t<li><code>1 <= m, n <= 50</code></li>\n\t<li><code>1 <= accounts[i][j] <= 100</code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Single-Threaded CPU",
|
||||
"titleSlug": "single-threaded-cpu",
|
||||
"content": "<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>\n\n<p>You have a single-threaded CPU that can process <strong>at most one</strong> task at a time and will act in the following way:</p>\n\n<ul>\n\t<li>If the CPU is idle and there are no available tasks to process, the CPU remains idle.</li>\n\t<li>If the CPU is idle and there are available tasks, the CPU will choose the one with the <strong>shortest processing time</strong>. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.</li>\n\t<li>Once a task is started, the CPU will <strong>process the entire task</strong> without stopping.</li>\n\t<li>The CPU can finish a task then start a new one instantly.</li>\n</ul>\n\n<p>Return <em>the order in which the CPU will process the tasks.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>Output:</strong> [0,2,3,1]\n<strong>Explanation: </strong>The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>Output:</strong> [4,3,2,0,1]\n<strong>Explanation</strong><strong>: </strong>The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>You are given <code>n</code> tasks labeled from <code>0</code> to <code>n - 1</code> represented by a 2D integer array <code>tasks</code>, where <code>tasks[i] = [enqueueTime<sub>i</sub>, processingTime<sub>i</sub>]</code> means that the <code>i<sup>th</sup></code> task will be available to process at <code>enqueueTime<sub>i</sub></code> and will take <code>processingTime<sub>i</sub></code><sub> </sub>to finish processing.</p>\n\n<p>You have a single-threaded CPU that can process <strong>at most one</strong> task at a time and will act in the following way:</p>\n\n<ul>\n\t<li>If the CPU is idle and there are no available tasks to process, the CPU remains idle.</li>\n\t<li>If the CPU is idle and there are available tasks, the CPU will choose the one with the <strong>shortest processing time</strong>. If multiple tasks have the same shortest processing time, it will choose the task with the smallest index.</li>\n\t<li>Once a task is started, the CPU will <strong>process the entire task</strong> without stopping.</li>\n\t<li>The CPU can finish a task then start a new one instantly.</li>\n</ul>\n\n<p>Return <em>the order in which the CPU will process the tasks.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[1,2],[2,4],[3,2],[4,1]]\n<strong>Output:</strong> [0,2,3,1]\n<strong>Explanation: </strong>The events go as follows: \n- At time = 1, task 0 is available to process. Available tasks = {0}.\n- Also at time = 1, the idle CPU starts processing task 0. Available tasks = {}.\n- At time = 2, task 1 is available to process. Available tasks = {1}.\n- At time = 3, task 2 is available to process. Available tasks = {1, 2}.\n- Also at time = 3, the CPU finishes task 0 and starts processing task 2 as it is the shortest. Available tasks = {1}.\n- At time = 4, task 3 is available to process. Available tasks = {1, 3}.\n- At time = 5, the CPU finishes task 2 and starts processing task 3 as it is the shortest. Available tasks = {1}.\n- At time = 6, the CPU finishes task 3 and starts processing task 1. Available tasks = {}.\n- At time = 10, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> tasks = [[7,10],[7,12],[7,5],[7,4],[7,2]]\n<strong>Output:</strong> [4,3,2,0,1]\n<strong>Explanation</strong><strong>: </strong>The events go as follows:\n- At time = 7, all the tasks become available. Available tasks = {0,1,2,3,4}.\n- Also at time = 7, the idle CPU starts processing task 4. Available tasks = {0,1,2,3}.\n- At time = 9, the CPU finishes task 4 and starts processing task 3. Available tasks = {0,1,2}.\n- At time = 13, the CPU finishes task 3 and starts processing task 2. Available tasks = {0,1}.\n- At time = 18, the CPU finishes task 2 and starts processing task 0. Available tasks = {1}.\n- At time = 28, the CPU finishes task 0 and starts processing task 1. Available tasks = {}.\n- At time = 40, the CPU finishes task 1 and becomes idle.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>tasks.length == n</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= enqueueTime<sub>i</sub>, processingTime<sub>i</sub> <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Splitting a String Into Descending Consecutive Values",
|
||||
"titleSlug": "splitting-a-string-into-descending-consecutive-values",
|
||||
"content": "<p>You are given a string <code>s</code> that consists of only digits.</p>\n\n<p>Check if we can split <code>s</code> into <strong>two or more non-empty substrings</strong> such that the <strong>numerical values</strong> of the substrings are in <strong>descending order</strong> and the <strong>difference</strong> between numerical values of every two <strong>adjacent</strong> <strong>substrings</strong> is equal to <code>1</code>.</p>\n\n<ul>\n\t<li>For example, the string <code>s = "0090089"</code> can be split into <code>["0090", "089"]</code> with numerical values <code>[90,89]</code>. The values are in descending order and adjacent values differ by <code>1</code>, so this way is valid.</li>\n\t<li>Another example, the string <code>s = "001"</code> can be split into <code>["0", "01"]</code>, <code>["00", "1"]</code>, or <code>["0", "0", "1"]</code>. However all the ways are invalid because they have numerical values <code>[0,1]</code>, <code>[0,1]</code>, and <code>[0,0,1]</code> respectively, all of which are not in descending order.</li>\n</ul>\n\n<p>Return <code>true</code> <em>if it is possible to split</em> <code>s</code> <em>as described above</em><em>, or </em><code>false</code><em> otherwise.</em></p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "1234"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> There is no valid way to split s.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "050043"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> s can be split into ["05", "004", "3"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "9080701"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> There is no valid way to split s.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 20</code></li>\n\t<li><code>s</code> only consists of digits.</li>\n</ul>\n",
|
||||
"content": "<p>You are given a string <code>s</code> that consists of only digits.</p>\n\n<p>Check if we can split <code>s</code> into <strong>two or more non-empty substrings</strong> such that the <strong>numerical values</strong> of the substrings are in <strong>descending order</strong> and the <strong>difference</strong> between numerical values of every two <strong>adjacent</strong> <strong>substrings</strong> is equal to <code>1</code>.</p>\n\n<ul>\n\t<li>For example, the string <code>s = "0090089"</code> can be split into <code>["0090", "089"]</code> with numerical values <code>[90,89]</code>. The values are in descending order and adjacent values differ by <code>1</code>, so this way is valid.</li>\n\t<li>Another example, the string <code>s = "001"</code> can be split into <code>["0", "01"]</code>, <code>["00", "1"]</code>, or <code>["0", "0", "1"]</code>. However all the ways are invalid because they have numerical values <code>[0,1]</code>, <code>[0,1]</code>, and <code>[0,0,1]</code> respectively, all of which are not in descending order.</li>\n</ul>\n\n<p>Return <code>true</code> <em>if it is possible to split</em> <code>s</code> <em>as described above</em><em>, or </em><code>false</code><em> otherwise.</em></p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "1234"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> There is no valid way to split s.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "050043"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> s can be split into ["05", "004", "3"] with numerical values [5,4,3].\nThe values are in descending order with adjacent values differing by 1.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "9080701"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> There is no valid way to split s.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 20</code></li>\n\t<li><code>s</code> only consists of digits.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Substrings of Size Three with Distinct Characters",
|
||||
"titleSlug": "substrings-of-size-three-with-distinct-characters",
|
||||
"content": "<p>A string is <strong>good</strong> if there are no repeated characters.</p>\n\n<p>Given a string <code>s</code>, return <em>the number of <strong>good substrings</strong> of length <strong>three </strong>in </em><code>s</code>.</p>\n\n<p>Note that if there are multiple occurrences of the same substring, every occurrence should be counted.</p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "xyzzaz"\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz". \nThe only good substring of length 3 is "xyz".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aababcabc"\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc".\nThe good substrings are "abc", "bca", "cab", and "abc".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>s</code> consists of lowercase English letters.</li>\n</ul>\n",
|
||||
"content": "<p>A string is <strong>good</strong> if there are no repeated characters.</p>\n\n<p>Given a string <code>s</code>, return <em>the number of <strong>good substrings</strong> of length <strong>three </strong>in </em><code>s</code>.</p>\n\n<p>Note that if there are multiple occurrences of the same substring, every occurrence should be counted.</p>\n\n<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "xyzzaz"\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> There are 4 substrings of size 3: "xyz", "yzz", "zza", and "zaz". \nThe only good substring of length 3 is "xyz".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aababcabc"\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> There are 7 substrings of size 3: "aab", "aba", "bab", "abc", "bca", "cab", and "abc".\nThe good substrings are "abc", "bca", "cab", and "abc".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>s</code> consists of lowercase English letters.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Taking Maximum Energy From the Mystic Dungeon",
|
||||
"titleSlug": "taking-maximum-energy-from-the-mystic-dungeon",
|
||||
"content": "<p>In a mystic dungeon, <code>n</code> magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.</p>\n\n<p>You have been cursed in such a way that after absorbing energy from magician <code>i</code>, you will be instantly transported to magician <code>(i + k)</code>. This process will be repeated until you reach the magician where <code>(i + k)</code> does not exist.</p>\n\n<p>In other words, you will choose a starting point and then teleport with <code>k</code> jumps until you reach the end of the magicians' sequence, <strong>absorbing all the energy</strong> during the journey.</p>\n\n<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<div class=\"example-block\" style=\"\n border-color: var(--border-tertiary);\n border-left-width: 2px;\n color: var(--text-secondary);\n font-size: .875rem;\n margin-bottom: 1rem;\n margin-top: 1rem;\n overflow: visible;\n padding-left: 1rem;\n\">\n<p><strong>Input:</strong> <span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> energy = [5,2,-10,-5,1], k = 3</span></p>\n\n<p><strong>Output:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> 3</span></p>\n\n<p><strong>Explanation:</strong> We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.</p>\n</div>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<div class=\"example-block\" style=\"\n border-color: var(--border-tertiary);\n border-left-width: 2px;\n color: var(--text-secondary);\n font-size: .875rem;\n margin-bottom: 1rem;\n margin-top: 1rem;\n overflow: visible;\n padding-left: 1rem;\n\">\n<p><strong>Input:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> energy = [-2,-3,-1], k = 2</span></p>\n\n<p><strong>Output:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> -1</span></p>\n\n<p><strong>Explanation:</strong> We can gain a total energy of -1 by starting from magician 2.</p>\n</div>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>\n\t<li><code>-1000 <= energy[i] <= 1000</code></li>\n\t<li><code>1 <= k <= energy.length - 1</code></li>\n</ul>\n\n<p> </p>\n",
|
||||
"content": "<p>In a mystic dungeon, <code>n</code> magicians are standing in a line. Each magician has an attribute that gives you energy. Some magicians can give you negative energy, which means taking energy from you.</p>\n\n<p>You have been cursed in such a way that after absorbing energy from magician <code>i</code>, you will be instantly transported to magician <code>(i + k)</code>. This process will be repeated until you reach the magician where <code>(i + k)</code> does not exist.</p>\n\n<p>In other words, you will choose a starting point and then teleport with <code>k</code> jumps until you reach the end of the magicians' sequence, <strong>absorbing all the energy</strong> during the journey.</p>\n\n<p>You are given an array <code>energy</code> and an integer <code>k</code>. Return the <strong>maximum</strong> possible energy you can gain.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<div class=\"example-block\" style=\"\n border-color: var(--border-tertiary);\n border-left-width: 2px;\n color: var(--text-secondary);\n font-size: .875rem;\n margin-bottom: 1rem;\n margin-top: 1rem;\n overflow: visible;\n padding-left: 1rem;\n\">\n<p><strong>Input:</strong> <span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> energy = [5,2,-10,-5,1], k = 3</span></p>\n\n<p><strong>Output:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> 3</span></p>\n\n<p><strong>Explanation:</strong> We can gain a total energy of 3 by starting from magician 1 absorbing 2 + 1 = 3.</p>\n</div>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<div class=\"example-block\" style=\"\n border-color: var(--border-tertiary);\n border-left-width: 2px;\n color: var(--text-secondary);\n font-size: .875rem;\n margin-bottom: 1rem;\n margin-top: 1rem;\n overflow: visible;\n padding-left: 1rem;\n\">\n<p><strong>Input:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> energy = [-2,-3,-1], k = 2</span></p>\n\n<p><strong>Output:</strong><span class=\"example-io\" style=\"\n font-family: Menlo,sans-serif;\n font-size: 0.85rem;\n\"> -1</span></p>\n\n<p><strong>Explanation:</strong> We can gain a total energy of -1 by starting from magician 2.</p>\n</div>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>\n\t<li><code>-1000 <= energy[i] <= 1000</code></li>\n\t<li><code>1 <= k <= energy.length - 1</code></li>\n</ul>\n\n<p> </p>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Truncate Sentence",
|
||||
"titleSlug": "truncate-sentence",
|
||||
"content": "<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of <strong>only</strong> uppercase and lowercase English letters (no punctuation).</p>\n\n<ul>\n\t<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, and <code>"hello world hello world"</code> are all sentences.</li>\n</ul>\n\n<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "Hello how are you Contestant", k = 4\n<strong>Output:</strong> "Hello how are you"\n<strong>Explanation:</strong>\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "What is the solution to this problem", k = 4\n<strong>Output:</strong> "What is the solution"\n<strong>Explanation:</strong>\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "chopper is not a tanuki", k = 5\n<strong>Output:</strong> "chopper is not a tanuki"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> is in the range <code>[1, the number of words in s]</code>.</li>\n\t<li><code>s</code> consist of only lowercase and uppercase English letters and spaces.</li>\n\t<li>The words in <code>s</code> are separated by a single space.</li>\n\t<li>There are no leading or trailing spaces.</li>\n</ul>\n",
|
||||
"content": "<p>A <strong>sentence</strong> is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of <strong>only</strong> uppercase and lowercase English letters (no punctuation).</p>\n\n<ul>\n\t<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, and <code>"hello world hello world"</code> are all sentences.</li>\n</ul>\n\n<p>You are given a sentence <code>s</code> and an integer <code>k</code>. You want to <strong>truncate</strong> <code>s</code> such that it contains only the <strong>first</strong> <code>k</code> words. Return <code>s</code><em> after <strong>truncating</strong> it.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "Hello how are you Contestant", k = 4\n<strong>Output:</strong> "Hello how are you"\n<strong>Explanation:</strong>\nThe words in s are ["Hello", "how" "are", "you", "Contestant"].\nThe first 4 words are ["Hello", "how", "are", "you"].\nHence, you should return "Hello how are you".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "What is the solution to this problem", k = 4\n<strong>Output:</strong> "What is the solution"\n<strong>Explanation:</strong>\nThe words in s are ["What", "is" "the", "solution", "to", "this", "problem"].\nThe first 4 words are ["What", "is", "the", "solution"].\nHence, you should return "What is the solution".</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "chopper is not a tanuki", k = 5\n<strong>Output:</strong> "chopper is not a tanuki"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>k</code> is in the range <code>[1, the number of words in s]</code>.</li>\n\t<li><code>s</code> consist of only lowercase and uppercase English letters and spaces.</li>\n\t<li>The words in <code>s</code> are separated by a single space.</li>\n\t<li>There are no leading or trailing spaces.</li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
@@ -6,7 +6,7 @@
|
||||
"boundTopicId": null,
|
||||
"title": "Widest Vertical Area Between Two Points Containing No Points",
|
||||
"titleSlug": "widest-vertical-area-between-two-points-containing-no-points",
|
||||
"content": "<p>Given <code>n</code> <code>points</code> on a 2D plane where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>, Return<em> the <strong>widest vertical area</strong> between two points such that no points are inside the area.</em></p>\n\n<p>A <strong>vertical area</strong> is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The <strong>widest vertical area</strong> is the one with the maximum width.</p>\n\n<p>Note that points <strong>on the edge</strong> of a vertical area <strong>are not</strong> considered included in the area.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/09/19/points3.png\" style=\"width: 276px; height: 371px;\" />\n<pre>\n<strong>Input:</strong> points = [[8,7],[9,9],[7,4],[9,7]]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> Both the red and the blue area are optimal.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n<strong>Output:</strong> 3\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == points.length</code></li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"content": "<p>Given <code>n</code> <code>points</code> on a 2D plane where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>, Return<em> the <strong>widest vertical area</strong> between two points such that no points are inside the area.</em></p>\n\n<p>A <strong>vertical area</strong> is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The <strong>widest vertical area</strong> is the one with the maximum width.</p>\n\n<p>Note that points <strong>on the edge</strong> of a vertical area <strong>are not</strong> considered included in the area.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/09/19/points3.png\" style=\"width: 276px; height: 371px;\" />\n<pre>\n<strong>Input:</strong> points = [[8,7],[9,9],[7,4],[9,7]]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> Both the red and the blue area are optimal.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]\n<strong>Output:</strong> 3\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == points.length</code></li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>9</sup></code></li>\n</ul>\n",
|
||||
"translatedTitle": null,
|
||||
"translatedContent": null,
|
||||
"isPaidOnly": false,
|
||||
|
Reference in New Issue
Block a user