1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

Compare commits

...

2 Commits

55 changed files with 17214 additions and 14332 deletions

View File

@ -1,6 +1,6 @@
# 力扣题库(完整版)
> 最后更新日期: **2023.11.27**
> 最后更新日期: **2023.12.09**
>
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件

File diff suppressed because it is too large Load Diff

View File

@ -18,10 +18,35 @@
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": "数学",
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": "二分查找",
"__typename": "TopicTagNode"
},
{
"name": "Number Theory",
"slug": "number-theory",
"translatedName": "数论",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"50\", \"totalSubmission\": \"67\", \"totalAcceptedRaw\": 50, \"totalSubmissionRaw\": 67, \"acRate\": \"74.6%\"}",
"stats": "{\"totalAccepted\": \"209\", \"totalSubmission\": \"258\", \"totalAcceptedRaw\": 209, \"totalSubmissionRaw\": 258, \"acRate\": \"81.0%\"}",
"hints": [
"Try to answer the query of asking GCD of a subarray in <code>O(1)</code> using sparse tables and preprocessing.",
"For every index <code>L</code>, lets find the subarray starting at the index <code>L</code> and maximizing gcd-sum.",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3210",
"questionFrontendId": "100134",
"questionFrontendId": "2947",
"categoryTitle": "Algorithms",
"boundTopicId": 2538343,
"title": "Count Beautiful Substrings I",
@ -12,13 +12,32 @@
"translatedContent": "<p>给你一个字符串 <code>s</code> 和一个正整数 <code>k</code> 。</p>\n\n<p>用 <code>vowels</code> 和 <code>consonants</code> 分别表示字符串中元音字母和辅音字母的数量。</p>\n\n<p>如果某个字符串满足以下条件,则称其为 <strong>美丽字符串</strong> </p>\n\n<ul>\n\t<li><code>vowels == consonants</code>,即元音字母和辅音字母的数量相等。</li>\n\t<li><code>(vowels * consonants) % k == 0</code>,即元音字母和辅音字母的数量的乘积能被 <code>k</code> 整除。</li>\n</ul>\n\n<p>返回字符串 <code>s</code> 中 <strong>非空美丽子字符串</strong> 的数量。</p>\n\n<p>子字符串是字符串中的一个连续字符序列。</p>\n\n<p>英语中的<strong> 元音字母 </strong>为 <code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code> 。</p>\n\n<p>英语中的<strong> 辅音字母 </strong>为除了元音字母之外的所有字母。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"baeyh\", k = 2\n<strong>输出:</strong>2\n<strong>解释:</strong>字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"b<em><strong>aeyh</strong></em>\"vowels = 2[\"a\",\"e\"]consonants = 2[\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"<em><strong>baey</strong></em>h\"vowels = 2[\"a\",\"e\"]consonants = 2[\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"abba\", k = 1\n<strong>输出:</strong>3\n<strong>解释:</strong>字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"<strong><em>ab</em></strong>ba\"vowels = 1[\"a\"]consonants = 1[\"b\"])。\n- 子字符串 \"ab<strong><em>ba</em></strong>\"vowels = 1[\"a\"]consonants = 1[\"b\"])。\n- 子字符串 \"<em><strong>abba</strong></em>\"vowels = 2[\"a\",\"a\"]consonants = 2[\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"bcdf\", k = 1\n<strong>输出:</strong>0\n<strong>解释:</strong>字符串 s 中没有美丽子字符串。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s.length &lt;= 1000</code></li>\n\t<li><code>1 &lt;= k &lt;= 1000</code></li>\n\t<li><code>s</code> 仅由小写英文字母组成。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 0,
"likes": 5,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "String",
"slug": "string",
"translatedName": "字符串",
"__typename": "TopicTagNode"
},
{
"name": "Enumeration",
"slug": "enumeration",
"translatedName": "枚举",
"__typename": "TopicTagNode"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum",
"translatedName": "前缀和",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"5.3K\", \"totalAcceptedRaw\": 2949, \"totalSubmissionRaw\": 5299, \"acRate\": \"55.7%\"}",
"stats": "{\"totalAccepted\": \"3.9K\", \"totalSubmission\": \"6.8K\", \"totalAcceptedRaw\": 3927, \"totalSubmissionRaw\": 6776, \"acRate\": \"58.0%\"}",
"hints": [
"Iterate over all substrings and maintain the frequencies of vowels and consonants."
],

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3208",
"questionFrontendId": "100132",
"questionFrontendId": "2949",
"categoryTitle": "Algorithms",
"boundTopicId": 2538345,
"title": "Count Beautiful Substrings II",
@ -12,13 +12,44 @@
"translatedContent": "<p>给你一个字符串 <code>s</code> 和一个正整数 <code>k</code> 。</p>\n\n<p>用 <code>vowels</code> 和 <code>consonants</code> 分别表示字符串中元音字母和辅音字母的数量。</p>\n\n<p>如果某个字符串满足以下条件,则称其为 <strong>美丽字符串</strong> </p>\n\n<ul>\n\t<li><code>vowels == consonants</code>,即元音字母和辅音字母的数量相等。</li>\n\t<li><code>(vowels * consonants) % k == 0</code>,即元音字母和辅音字母的数量的乘积能被 <code>k</code> 整除。</li>\n</ul>\n\n<p>返回字符串 <code>s</code> 中 <strong>非空美丽子字符串</strong> 的数量。</p>\n\n<p>子字符串是字符串中的一个连续字符序列。</p>\n\n<p>英语中的<strong> 元音字母 </strong>为 <code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code> 和 <code>'u'</code> 。</p>\n\n<p>英语中的<strong> 辅音字母 </strong>为除了元音字母之外的所有字母。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"baeyh\", k = 2\n<strong>输出:</strong>2\n<strong>解释:</strong>字符串 s 中有 2 个美丽子字符串。\n- 子字符串 \"b<em><strong>aeyh</strong></em>\"vowels = 2[\"a\",\"e\"]consonants = 2[\"y\",\"h\"])。\n可以看出字符串 \"aeyh\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n- 子字符串 \"<em><strong>baey</strong></em>h\"vowels = 2[\"a\",\"e\"]consonants = 2[\"b\",\"y\"])。\n可以看出字符串 \"baey\" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。\n可以证明字符串 s 中只有 2 个美丽子字符串。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"abba\", k = 1\n<strong>输出:</strong>3\n<strong>解释:</strong>字符串 s 中有 3 个美丽子字符串。\n- 子字符串 \"<strong><em>ab</em></strong>ba\"vowels = 1[\"a\"]consonants = 1[\"b\"])。\n- 子字符串 \"ab<strong><em>ba</em></strong>\"vowels = 1[\"a\"]consonants = 1[\"b\"])。\n- 子字符串 \"<em><strong>abba</strong></em>\"vowels = 2[\"a\",\"a\"]consonants = 2[\"b\",\"b\"])。\n可以证明字符串 s 中只有 3 个美丽子字符串。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>s = \"bcdf\", k = 1\n<strong>输出:</strong>0\n<strong>解释:</strong>字符串 s 中没有美丽子字符串。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>\n\t<li><code>1 &lt;= k &lt;= 1000</code></li>\n\t<li><code>s</code> 仅由小写英文字母组成。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 5,
"likes": 12,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table",
"translatedName": "哈希表",
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": "数学",
"__typename": "TopicTagNode"
},
{
"name": "String",
"slug": "string",
"translatedName": "字符串",
"__typename": "TopicTagNode"
},
{
"name": "Number Theory",
"slug": "number-theory",
"translatedName": "数论",
"__typename": "TopicTagNode"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum",
"translatedName": "前缀和",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +167,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"895\", \"totalSubmission\": \"4K\", \"totalAcceptedRaw\": 895, \"totalSubmissionRaw\": 3972, \"acRate\": \"22.5%\"}",
"stats": "{\"totalAccepted\": \"1.9K\", \"totalSubmission\": \"5.9K\", \"totalAcceptedRaw\": 1868, \"totalSubmissionRaw\": 5900, \"acRate\": \"31.7%\"}",
"hints": [
"For the given <code>k</code> find all the <code>x</code> integers such that <code>x^2 % k == 0</code>. Notice, that there arent many such candidates.",
"We can iterate over all such <code>x</codes> values and count the number of substrings such that <code>vowels == consonants == x</code>.",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的正整数数组&nbsp;<code>heights</code>&nbsp;,其中&nbsp;<code>heights[i]</code>&nbsp;表示第 <code>i</code>&nbsp;栋建筑的高度。</p>\n\n<p>如果一个人在建筑&nbsp;<code>i</code>&nbsp;,且存在&nbsp;<code>i &lt; j</code>&nbsp;的建筑&nbsp;<code>j</code>&nbsp;满足&nbsp;<code>heights[i] &lt; heights[j]</code>&nbsp;,那么这个人可以移动到建筑&nbsp;<code>j</code>&nbsp;。</p>\n\n<p>给你另外一个数组&nbsp;<code>queries</code>&nbsp;,其中&nbsp;<code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>&nbsp;。第&nbsp;<code>i</code>&nbsp;个查询中Alice 在建筑&nbsp;<code>a<sub>i</sub></code> Bob 在建筑&nbsp;<code>b<sub>i</sub></code><sub>&nbsp;</sub>。</p>\n\n<p>请你能返回一个数组&nbsp;<code>ans</code>&nbsp;,其中&nbsp;<code>ans[i]</code>&nbsp;是第&nbsp;<code>i</code>&nbsp;个查询中Alice 和 Bob 可以相遇的&nbsp;<strong>最左边的建筑</strong>&nbsp;。如果对于查询&nbsp;<code>i</code>&nbsp;Alice<em> </em>和<em> </em>Bob 不能相遇,令&nbsp;<code>ans[i]</code> 为&nbsp;<code>-1</code>&nbsp;。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<b>输入:</b>heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]\n<b>输出:</b>[2,5,-1,5,2]\n<b>解释:</b>第一个查询中Alice 和 Bob 可以移动到建筑 2 ,因为 heights[0] &lt; heights[2] 且 heights[1] &lt; heights[2] 。\n第二个查询中Alice 和 Bob 可以移动到建筑 5 ,因为 heights[0] &lt; heights[5] 且 heights[3] &lt; heights[5] 。\n第三个查询中Alice 无法与 Bob 相遇,因为 Alice 不能移动到任何其他建筑。\n第四个查询中Alice 和 Bob 可以移动到建筑 5 ,因为 heights[3] &lt; heights[5] 且 heights[4] &lt; heights[5] 。\n第五个查询中Alice 和 Bob 已经在同一栋建筑中。\n对于 ans[i] != -1 ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<b>输入:</b>heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]\n<b>输出:</b>[7,6,-1,4,6]\n<strong>解释:</strong>第一个查询中Alice 可以直接移动到 Bob 的建筑,因为 heights[0] &lt; heights[7] 。\n第二个查询中Alice 和 Bob 可以移动到建筑 6 ,因为 heights[3] &lt; heights[6] 且 heights[5] &lt; heights[6] 。\n第三个查询中Alice 无法与 Bob 相遇,因为 Bob 不能移动到任何其他建筑。\n第四个查询中Alice 和 Bob 可以移动到建筑 4 ,因为 heights[3] &lt; heights[4] 且 heights[0] &lt; heights[4] 。\n第五个查询中Alice 可以直接移动到 Bob 的建筑,因为 heights[1] &lt; heights[6] 。\n对于 ans[i] != -1 ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。\n对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= heights.length &lt;= 5 * 10<sup>4</sup></code></li>\n\t<li><code>1 &lt;= heights[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>\n\t<li><code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>\n\t<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= heights.length - 1</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 15,
"likes": 16,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@ -179,7 +179,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.6K\", \"totalSubmission\": \"5.8K\", \"totalAcceptedRaw\": 2617, \"totalSubmissionRaw\": 5784, \"acRate\": \"45.2%\"}",
"stats": "{\"totalAccepted\": \"2.8K\", \"totalSubmission\": \"6.1K\", \"totalAcceptedRaw\": 2794, \"totalSubmissionRaw\": 6113, \"acRate\": \"45.7%\"}",
"hints": [
"For each query <code>[x, y]</code>, if <code>x > y</code>, swap <code>x</code> and <code>y</code>. Now, we can assume that <code>x <= y</code>.",
"For each query <code>[x, y]</code>, if <code>x == y</code> or <code>heights[x] < heights[y]</code>, then the answer is <code>y</code> since <code>x ≤ y</code>.",

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3211",
"questionFrontendId": "100135",
"questionFrontendId": "2945",
"categoryTitle": "Algorithms",
"boundTopicId": 2539696,
"title": "Find Maximum Non-decreasing Array Length",
@ -12,13 +12,56 @@
"translatedContent": "<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;。</p>\n\n<p>你可以执行任意次操作。每次操作中,你需要选择一个 <strong>子数组</strong>&nbsp;,并将这个子数组用它所包含元素的 <strong>和</strong>&nbsp;替换。比方说,给定数组是&nbsp;<code>[1,3,5,6]</code>&nbsp;,你可以选择子数组&nbsp;<code>[3,5]</code>&nbsp;,用子数组的和 <code>8</code>&nbsp;替换掉子数组,然后数组会变为&nbsp;<code>[1,8,6]</code>&nbsp;。</p>\n\n<p>请你返回执行任意次操作以后,可以得到的 <strong>最长非递减</strong>&nbsp;数组的长度。</p>\n\n<p><strong>子数组</strong>&nbsp;指的是一个数组中一段连续 <strong>非空</strong>&nbsp;的元素序列。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>nums = [5,2,2]\n<b>输出:</b>1\n<strong>解释:</strong>这个长度为 3 的数组不是非递减的。\n我们有 2 种方案使数组长度为 2 。\n第一种选择子数组 [2,2] ,对数组执行操作后得到 [5,4] 。\n第二种选择子数组 [5,2] ,对数组执行操作后得到 [7,2] 。\n这两种方案中数组最后都不是 <strong>非递减</strong>&nbsp;的,所以不是可行的答案。\n如果我们选择子数组 [5,2,2] ,并将它替换为 [9] ,数组变成非递减的。\n所以答案为 1 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<b>输入:</b>nums = [1,2,3,4]\n<b>输出:</b>4\n<b>解释:</b>数组已经是非递减的。所以答案为 4 。\n</pre>\n\n<p><strong>示例 3</strong></p>\n\n<pre>\n<b>输入:</b>nums = [4,3,2,6]\n<b>输出:</b>3\n<b>解释:</b>将 [3,2] 替换为 [5] ,得到数组 [4,5,6] ,它是非递减的。\n最大可能的答案为 3 。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 8,
"likes": 15,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Stack",
"slug": "stack",
"translatedName": "栈",
"__typename": "TopicTagNode"
},
{
"name": "Queue",
"slug": "queue",
"translatedName": "队列",
"__typename": "TopicTagNode"
},
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": "二分查找",
"__typename": "TopicTagNode"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming",
"translatedName": "动态规划",
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Queue",
"slug": "monotonic-queue",
"translatedName": "单调队列",
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Stack",
"slug": "monotonic-stack",
"translatedName": "单调栈",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +179,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"339\", \"totalSubmission\": \"2.5K\", \"totalAcceptedRaw\": 339, \"totalSubmissionRaw\": 2523, \"acRate\": \"13.4%\"}",
"stats": "{\"totalAccepted\": \"931\", \"totalSubmission\": \"3.8K\", \"totalAcceptedRaw\": 931, \"totalSubmissionRaw\": 3798, \"acRate\": \"24.5%\"}",
"hints": [
"Let <code>dp[i]</code> be the maximum number of elements in the increasing sequence after processing the first <code>i</code> elements of the original array.",
"We have <code>dp[0] = 0</code>. <code>dp[i + 1] >= dp[i]</code> (since if we have the solution for the first <code>i</code> elements, we can always merge the last one of the first <code>i + 1</code> elements which is <code>nums[i]</code> into the solution of the first <code>i</code> elements.",

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3194",
"questionFrontendId": "100121",
"questionFrontendId": "2942",
"categoryTitle": "Algorithms",
"boundTopicId": 2539393,
"title": "Find Words Containing Character",
@ -18,7 +18,20 @@
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "String",
"slug": "string",
"translatedName": "字符串",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"2.3K\", \"totalSubmission\": \"2.5K\", \"totalAcceptedRaw\": 2271, \"totalSubmissionRaw\": 2466, \"acRate\": \"92.1%\"}",
"stats": "{\"totalAccepted\": \"3.5K\", \"totalSubmission\": \"3.9K\", \"totalAcceptedRaw\": 3468, \"totalSubmissionRaw\": 3871, \"acRate\": \"89.6%\"}",
"hints": [
"Use two nested loops."
],

View File

@ -2,23 +2,42 @@
"data": {
"question": {
"questionId": "3219",
"questionFrontendId": "100142",
"questionFrontendId": "2948",
"categoryTitle": "Algorithms",
"boundTopicId": 2538344,
"title": "Make Lexicographically Smallest Array by Swapping Elements",
"titleSlug": "make-lexicographically-smallest-array-by-swapping-elements",
"content": "<p>You are given a <strong>0-indexed</strong> array of <strong>positive</strong> integers <code>nums</code> and a <strong>positive</strong> integer <code>limit</code>.</p>\n\n<p>In one operation, you can choose any two indices <code>i</code> and <code>j</code> and swap <code>nums[i]</code> and <code>nums[j]</code> <strong>if</strong> <code>|nums[i] - nums[j]| &lt;= limit</code>.</p>\n\n<p>Return <em>the <strong>lexicographically smallest array</strong> that can be obtained by performing the operation any number of times</em>.</p>\n\n<p>An array <code>a</code> is lexicographically smaller than an array <code>b</code> if in the first position where <code>a</code> and <code>b</code> differ, array <code>a</code> has an element that is less than the corresponding element in <code>b</code>. For example, the array <code>[2,10,3]</code> is lexicographically smaller than the array <code>[10,2,3]</code> because they differ at index <code>0</code> and <code>2 &lt; 10</code>.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,5,3,9,8], limit = 2\n<strong>Output:</strong> [1,3,5,8,9]\n<strong>Explanation:</strong> Apply the operation 2 times:\n- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]\n- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\nNote that it may be possible to get the same result by doing different operations.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,7,6,18,2,1], limit = 3\n<strong>Output:</strong> [1,6,7,18,1,2]\n<strong>Explanation:</strong> Apply the operation 3 times:\n- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]\n- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]\n- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]\nWe cannot obtain a lexicographically smaller array by applying any more operations.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,7,28,19,10], limit = 3\n<strong>Output:</strong> [1,7,28,19,10]\n<strong>Explanation:</strong> [1,7,28,19,10] is the lexicographically smallest array we can obtain because we cannot apply the operation on any two indices.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedTitle": "交换得到字典序最小的数组",
"translatedContent": "<p>给你一个下标从 <strong>0 </strong>开始的 <strong>正整数</strong> 数组 <code>nums</code> 和一个 <strong>正整数</strong> <code>limit</code> 。</p>\n\n<p>在一次操作中,你可以选择任意两个下标 <code>i</code> 和 <code>j</code><strong>如果</strong> 满足 <code>|nums[i] - nums[j]| &lt;= limit</code> ,则交换 <code>nums[i]</code> 和 <code>nums[j]</code> 。</p>\n\n<p>返回执行任意次操作后能得到的 <strong>字典序最小的数组</strong><em> </em>。</p>\n\n<p>如果在数组 <code>a</code> 和数组 <code>b</code> 第一个不同的位置上,数组 <code>a</code> 中的对应字符比数组 <code>b</code> 中的对应字符的字典序更小,则认为数组 <code>a</code> 就比数组 <code>b</code> 字典序更小。例如,数组 <code>[2,10,3]</code> 比数组 <code>[10,2,3]</code> 字典序更小,下标 <code>0</code> 处是两个数组第一个不同的位置,且 <code>2 &lt; 10</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,5,3,9,8], limit = 2\n<strong>输出:</strong>[1,3,5,8,9]\n<strong>解释:</strong>执行 2 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,3,5,9,8] 。\n- 交换 nums[3] 和 nums[4] 。数组变为 [1,3,5,8,9] 。\n即便执行更多次操作也无法得到字典序更小的数组。\n注意执行不同的操作也可能会得到相同的结果。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,7,6,18,2,1], limit = 3\n<strong>输出:</strong>[1,6,7,18,1,2]\n<strong>解释:</strong>执行 3 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,6,7,18,2,1] 。\n- 交换 nums[0] 和 nums[4] 。数组变为 [2,6,7,18,1,1] 。\n- 交换 nums[0] 和 nums[5] 。数组变为 [1,6,7,18,1,2] 。\n即便执行更多次操作也无法得到字典序更小的数组。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,7,28,19,10], limit = 3\n<strong>输出:</strong>[1,7,28,19,10]\n<strong>解释:</strong>[1,7,28,19,10] 是字典序最小的数组,因为不管怎么选择下标都无法执行操作。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"translatedContent": "<p>给你一个下标从 <strong>0 </strong>开始的 <strong>正整数</strong> 数组 <code>nums</code> 和一个 <strong>正整数</strong> <code>limit</code> 。</p>\n\n<p>在一次操作中,你可以选择任意两个下标 <code>i</code> 和 <code>j</code><strong>如果</strong> 满足 <code>|nums[i] - nums[j]| &lt;= limit</code> ,则交换 <code>nums[i]</code> 和 <code>nums[j]</code> 。</p>\n\n<p>返回执行任意次操作后能得到的 <strong>字典序最小的数组</strong><em> </em>。</p>\n\n<p>如果在数组 <code>a</code> 和数组 <code>b</code> 第一个不同的位置上,数组 <code>a</code> 中的对应元素比数组 <code>b</code> 中的对应元素的字典序更小,则认为数组 <code>a</code> 就比数组 <code>b</code> 字典序更小。例如,数组 <code>[2,10,3]</code> 比数组 <code>[10,2,3]</code> 字典序更小,下标 <code>0</code> 处是两个数组第一个不同的位置,且 <code>2 &lt; 10</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,5,3,9,8], limit = 2\n<strong>输出:</strong>[1,3,5,8,9]\n<strong>解释:</strong>执行 2 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,3,5,9,8] 。\n- 交换 nums[3] 和 nums[4] 。数组变为 [1,3,5,8,9] 。\n即便执行更多次操作也无法得到字典序更小的数组。\n注意执行不同的操作也可能会得到相同的结果。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,7,6,18,2,1], limit = 3\n<strong>输出:</strong>[1,6,7,18,1,2]\n<strong>解释:</strong>执行 3 次操作:\n- 交换 nums[1] 和 nums[2] 。数组变为 [1,6,7,18,2,1] 。\n- 交换 nums[0] 和 nums[4] 。数组变为 [2,6,7,18,1,1] 。\n- 交换 nums[0] 和 nums[5] 。数组变为 [1,6,7,18,1,2] 。\n即便执行更多次操作也无法得到字典序更小的数组。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>nums = [1,7,28,19,10], limit = 3\n<strong>输出:</strong>[1,7,28,19,10]\n<strong>解释:</strong>[1,7,28,19,10] 是字典序最小的数组,因为不管怎么选择下标都无法执行操作。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 12,
"likes": 24,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Union Find",
"slug": "union-find",
"translatedName": "并查集",
"__typename": "TopicTagNode"
},
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Sorting",
"slug": "sorting",
"translatedName": "排序",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.7K\", \"totalSubmission\": \"5.1K\", \"totalAcceptedRaw\": 1699, \"totalSubmissionRaw\": 5082, \"acRate\": \"33.4%\"}",
"stats": "{\"totalAccepted\": \"2.9K\", \"totalSubmission\": \"6.9K\", \"totalAcceptedRaw\": 2945, \"totalSubmissionRaw\": 6932, \"acRate\": \"42.5%\"}",
"hints": [
"Construct a virtual graph where all elements in <code>nums</code> are nodes and the pairs satisfying the condition have an edge between them.",
"Instead of constructing all edges, we only care about the connected components.",

View File

@ -12,7 +12,7 @@
"translatedContent": "<p>给你三个字符串 <code>s1</code>、<code>s2</code> 和 <code>s3</code>。 你可以根据需要对这三个字符串执行以下操作 <strong>任意次数</strong> <!-- notionvc: b5178de7-3318-4129-b7d9-726b47e90621 -->。</p>\n\n<p>在每次操作中,你可以选择其中一个长度至少为 <code>2</code> 的字符串 <!-- notionvc: 3342ac46-33c8-4010-aacd-e58678ce31ef --> 并删除其 <strong>最右位置上</strong> 的字符。</p>\n\n<p>如果存在某种方法能够使这三个字符串相等,请返回使它们相等所需的 <strong>最小</strong> 操作次数;否则,返回 <code>-1</code>。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>s1 = \"abc\"s2 = \"abb\"s3 = \"ab\"\n<strong>输出:</strong>2\n<strong>解释:</strong>对 s1 和 s2 进行一次操作后,可以得到三个相等的字符串。\n可以证明不可能用少于两次操作使它们相等。</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>s1 = \"dac\"s2 = \"bac\"s3 = \"cac\"\n<strong>输出:</strong>-1\n<strong>解释:</strong>因为 s1 和 s2 的最左位置上的字母<!-- notionvc: 47239f7c-eec1-49f8-af79-c206ec88cb07 -->不相等,所以无论进行多少次操作,它们都不可能相等。因此答案是 -1 。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s1.length, s2.length, s3.length &lt;= 100</code></li>\n\t<li><code>s1</code>、<code>s2</code> 和 <code>s3</code> 仅由小写英文字母组成。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 7,
"likes": 8,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"5.2K\", \"totalSubmission\": \"11.5K\", \"totalAcceptedRaw\": 5237, \"totalSubmissionRaw\": 11484, \"acRate\": \"45.6%\"}",
"stats": "{\"totalAccepted\": \"5.5K\", \"totalSubmission\": \"12K\", \"totalAcceptedRaw\": 5489, \"totalSubmissionRaw\": 11952, \"acRate\": \"45.9%\"}",
"hints": [
"Calculate the length of the longest common prefix of the <code>3</code> strings."
],

View File

@ -2,23 +2,48 @@
"data": {
"question": {
"questionId": "3215",
"questionFrontendId": "100139",
"questionFrontendId": "2946",
"categoryTitle": "Algorithms",
"boundTopicId": 2538342,
"title": "Matrix Similarity After Cyclic Shifts",
"titleSlug": "matrix-similarity-after-cyclic-shifts",
"content": "<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>mat</code> and an integer <code>k</code>. You have to cyclically <strong>right</strong> shift <strong>odd</strong> indexed rows <code>k</code> times and cyclically <strong>left</strong> shift <strong>even</strong> indexed rows <code>k</code> times.</p>\n\n<p>Return <code>true</code> <em>if the initial and final matrix are exactly the same and </em><code>false</code> <em>otherwise.</em></p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\n<strong>Output:</strong> true\n<strong>Explanation:</strong>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png\" style=\"width: 500px; height: 117px;\" />\n\nInitially, the matrix looks like the first figure. \nSecond figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.\nThird figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.\nTherefore, return true.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> mat = [[2,2],[2,2]], k = 3\n<strong>Output:</strong> true\n<strong>Explanation:</strong> As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> mat = [[1,2]], k = 1\n<strong>Output:</strong> false\n<strong>Explanation:</strong> After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.\n</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= mat.length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>\n\t<li><code>1 &lt;= k &lt;= 50</code></li>\n</ul>\n",
"translatedTitle": "循环移位后的矩阵相似检查",
"translatedContent": "<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>mat</code> 和一个整数 <code>k</code> 。请你将矩阵中的<strong> 奇数</strong> 行循环 <strong>右</strong> 移 <code>k</code> 次,<strong>偶数</strong> 行循环 <strong>左</strong> 移 <code>k</code> 次。</p>\n\n<p>如果初始矩阵和最终矩阵完全相同,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\n<strong>输出:</strong>true\n<strong>解释:</strong>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png\" style=\"width: 500px; height: 117px;\" />\n\n初始矩阵如图一所示。\n图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。\n图三是经过两次循环移位后的最终矩阵状态与初始矩阵相同。\n因此返回 true 。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[2,2],[2,2]], k = 3\n<strong>输出:</strong>true\n<strong>解释:</strong>由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[1,2]], k = 1\n<strong>输出:</strong>false\n<strong>解释:</strong>循环移位一次后mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= mat.length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>\n\t<li><code>1 &lt;= k &lt;= 50</code></li>\n</ul>\n",
"translatedContent": "<p>给你一个<strong>下标从 0 开始</strong>且大小为 <code>m x n</code> 的整数矩阵 <code>mat</code> 和一个整数 <code>k</code> 。请你将矩阵中的<strong> 奇数</strong> 行循环 <strong>右</strong> 移 <code>k</code> 次,<strong>偶数</strong> 行循环 <strong>左</strong> 移 <code>k</code> 次。</p>\n\n<p>如果初始矩阵和最终矩阵完全相同,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2\n<strong>输出:</strong>true\n<strong>解释:</strong>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png\" style=\"width: 500px; height: 117px;\" />\n\n初始矩阵如图一所示。\n图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。\n图三是经过两次循环移位后的最终矩阵状态与初始矩阵相同。\n因此返回 true 。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[2,2],[2,2]], k = 3\n<strong>输出:</strong>true\n<strong>解释:</strong>由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<pre>\n<strong>输入:</strong>mat = [[1,2]], k = 1\n<strong>输出:</strong>false\n<strong>解释:</strong>循环移位一次后mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= mat.length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>\n\t<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>\n\t<li><code>1 &lt;= k &lt;= 50</code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 2,
"likes": 5,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": true, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": "数学",
"__typename": "TopicTagNode"
},
{
"name": "Matrix",
"slug": "matrix",
"translatedName": "矩阵",
"__typename": "TopicTagNode"
},
{
"name": "Simulation",
"slug": "simulation",
"translatedName": "模拟",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.6K\", \"totalSubmission\": \"6K\", \"totalAcceptedRaw\": 3562, \"totalSubmissionRaw\": 5988, \"acRate\": \"59.5%\"}",
"stats": "{\"totalAccepted\": \"4.9K\", \"totalSubmission\": \"8.1K\", \"totalAcceptedRaw\": 4907, \"totalSubmissionRaw\": 8054, \"acRate\": \"60.9%\"}",
"hints": [
"You can reduce <code>k</code> shifts to <code>(k % n)</code> shifts as after <code>n</code> shifts the matrix will become similar to the initial matrix."
],

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3214",
"questionFrontendId": "100138",
"questionFrontendId": "2943",
"categoryTitle": "Algorithms",
"boundTopicId": 2539398,
"title": "Maximize Area of Square Hole in Grid",
@ -12,13 +12,26 @@
"translatedContent": "<p>给你一个网格图,由&nbsp;<code>n + 2</code>&nbsp;条 <strong>横线段</strong>&nbsp;和&nbsp;<code>m + 2</code>&nbsp;条&nbsp;<strong>竖线段</strong>&nbsp;组成,一开始所有区域均为&nbsp;<code>1 x 1</code>&nbsp;的单元格。</p>\n\n<p>所有线段的编号从 <strong>1</strong>&nbsp;开始。</p>\n\n<p>给你两个整数&nbsp;<code>n</code> 和&nbsp;<code>m</code>&nbsp;。</p>\n\n<p>同时给你两个整数数组&nbsp;<code>hBars</code> 和&nbsp;<code>vBars</code>&nbsp;。</p>\n\n<ul>\n\t<li><code>hBars</code> 包含区间&nbsp;<code>[2, n + 1]</code>&nbsp;内&nbsp;<strong>互不相同</strong>&nbsp;的横线段编号。</li>\n\t<li><code>vBars</code>&nbsp;包含&nbsp;<code>[2, m + 1]</code>&nbsp;内&nbsp;<strong>互不相同的</strong>&nbsp;竖线段编号。</li>\n</ul>\n\n<p>如果满足以下条件之一,你可以 <strong>移除</strong>&nbsp;两个数组中的部分线段:</p>\n\n<ul>\n\t<li>如果移除的是横线段,它必须是&nbsp;<code>hBars</code>&nbsp;中的值。</li>\n\t<li>如果移除的是竖线段,它必须是&nbsp;<code>vBars</code>&nbsp;中的值。</li>\n</ul>\n\n<p>请你返回移除一些线段后(<strong>可能不移除任何线段)</strong>,剩余网格图中 <strong>最大正方形</strong>&nbsp;空洞的面积,正方形空洞的意思是正方形 <strong>内部</strong> 不含有任何线段。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/11/05/screenshot-from-2023-11-05-22-40-25.png\" style=\"width: 411px; height: 220px;\" /></p>\n\n<pre>\n<b>输入:</b>n = 2, m = 1, hBars = [2,3], vBars = [2]\n<b>输出:</b>4\n<b>解释:</b>左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/11/04/screenshot-from-2023-11-04-17-01-02.png\" style=\"width: 368px; height: 145px;\" /></p>\n\n<pre>\n<b>输入:</b>n = 1, m = 1, hBars = [2], vBars = [2]\n<b>输出:</b>4\n<b>解释:</b>左边的图是一开始的网格图。\n横线编号的范围是区间 [1,3] ,竖线编号的范围是区间 [1,3] 。\n可以移除的横线段为 [2] ,竖线段为 [2] 。\n一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 4。\n无法得到面积大于 4 的正方形空洞。\n所以答案为 4 。\n</pre>\n\n<p><strong class=\"example\">示例 3</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/11/05/screenshot-from-2023-11-05-22-33-35.png\" style=\"width: 648px; height: 218px;\" /></p>\n\n<pre>\n<b>输入:</b>n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]\n<b>输出:</b>9\n<b>解释:</b>左边的图是一开始的网格图。\n横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,5] 。\n可以移除的横线段为 [2,3] ,竖线段为 [2,3,4] 。\n一种得到最大正方形面积的方法是移除横线段 2、3 和竖线段 3、4 。\n操作后得到的网格图如右图所示。\n正方形空洞面积为 9。\n无法得到面积大于 9 的正方形空洞。\n所以答案为 9 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>\n\t<li><code>1 &lt;= hBars.length &lt;= 100</code></li>\n\t<li><code>2 &lt;= hBars[i] &lt;= n + 1</code></li>\n\t<li><code>1 &lt;= vBars.length &lt;= 100</code></li>\n\t<li><code>2 &lt;= vBars[i] &lt;= m + 1</code></li>\n\t<li><code>hBars</code>&nbsp;中的值互不相同。</li>\n\t<li><code>vBars</code> 中的值互不相同。</li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 0,
"likes": 3,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Sorting",
"slug": "sorting",
"translatedName": "排序",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.7K\", \"totalSubmission\": \"5K\", \"totalAcceptedRaw\": 1713, \"totalSubmissionRaw\": 4967, \"acRate\": \"34.5%\"}",
"stats": "{\"totalAccepted\": \"2.4K\", \"totalSubmission\": \"6.3K\", \"totalAcceptedRaw\": 2365, \"totalSubmissionRaw\": 6305, \"acRate\": \"37.5%\"}",
"hints": [
"Sort <code>hBars</code> and <code>vBars</code> and consider them separately.",
"Compute the longest sequence of consecutive integer values in each array, denoted as <code>[hx, hy]</code> and <code>[vx, vy]</code>, respectively.",

View File

@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"10.5K\", \"totalAcceptedRaw\": 3079, \"totalSubmissionRaw\": 10461, \"acRate\": \"29.4%\"}",
"stats": "{\"totalAccepted\": \"3.2K\", \"totalSubmission\": \"10.8K\", \"totalAcceptedRaw\": 3220, \"totalSubmissionRaw\": 10811, \"acRate\": \"29.8%\"}",
"hints": [
"Iterate over bits from most significant to least significant.",
"For the <code>i<sup>th</sup></code> bit, if both <code>a</code> and <code>b</code> have the same value, we can always make <code>x</code>s <code>i<sup>th</sup></code> bit different from <code>a</code> and <code>b</code>, so <code>a ^ x</code> and <code>b ^ x</code> both have the <code>i<sup>th</sup></cod> bit set.",

View File

@ -2,7 +2,7 @@
"data": {
"question": {
"questionId": "3209",
"questionFrontendId": "100133",
"questionFrontendId": "2944",
"categoryTitle": "Algorithms",
"boundTopicId": 2539684,
"title": "Minimum Number of Coins for Fruits",
@ -12,13 +12,38 @@
"translatedContent": "<p>你在一个水果超市里,货架上摆满了玲琅满目的奇珍异果。</p>\n\n<p>给你一个下标从 <strong>1</strong>&nbsp;开始的数组&nbsp;<code>prices</code>&nbsp;,其中&nbsp;<code>prices[i]</code>&nbsp;表示你购买第 <code>i</code>&nbsp;个水果需要花费的金币数目。</p>\n\n<p>水果超市有如下促销活动:</p>\n\n<ul>\n\t<li>如果你花费 <code>price[i]</code>&nbsp;购买了水果&nbsp;<code>i</code>&nbsp;,那么接下来的 <code>i</code>&nbsp;个水果你都可以免费获得。</li>\n</ul>\n\n<p><strong>注意</strong>&nbsp;,即使你&nbsp;<strong>可以</strong>&nbsp;免费获得水果&nbsp;<code>j</code>&nbsp;,你仍然可以花费&nbsp;<code>prices[j]</code>&nbsp;个金币去购买它以便能免费获得接下来的 <code>j</code>&nbsp;个水果。</p>\n\n<p>请你返回获得所有水果所需要的 <strong>最少</strong>&nbsp;金币数。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<b>输入:</b>prices = [3,1,2]\n<b>输出:</b>4\n<b>解释</b><strong></strong>你可以按如下方法获得所有水果:\n- 花 3 个金币购买水果 1 ,然后免费获得水果 2 。\n- 花 1 个金币购买水果 2 ,然后免费获得水果 3 。\n- 免费获得水果 3 。\n注意虽然你可以免费获得水果 2 ,但你还是花 1 个金币去购买它,因为这样的总花费最少。\n购买所有水果需要最少花费 4 个金币。\n</pre>\n\n<p><strong class=\"example\">示例 2</strong></p>\n\n<pre>\n<b>输入:</b>prices = [1,10,1,1]\n<b>输出:</b>2\n<b>解释:</b>你可以按如下方法获得所有水果:\n- 花 1 个金币购买水果 1 ,然后免费获得水果 2 。\n- 免费获得水果 2 。\n- 花 1 个金币购买水果 3 ,然后免费获得水果 4 。\n- 免费获得水果 4 。\n购买所有水果需要最少花费 2 个金币。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= prices.length &lt;= 1000</code></li>\n\t<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 3,
"likes": 9,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [],
"topicTags": [
{
"name": "Queue",
"slug": "queue",
"translatedName": "队列",
"__typename": "TopicTagNode"
},
{
"name": "Array",
"slug": "array",
"translatedName": "数组",
"__typename": "TopicTagNode"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming",
"translatedName": "动态规划",
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Queue",
"slug": "monotonic-queue",
"translatedName": "单调队列",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.8K\", \"totalSubmission\": \"3.5K\", \"totalAcceptedRaw\": 1809, \"totalSubmissionRaw\": 3464, \"acRate\": \"52.2%\"}",
"stats": "{\"totalAccepted\": \"3.1K\", \"totalSubmission\": \"5.2K\", \"totalAcceptedRaw\": 3087, \"totalSubmissionRaw\": 5221, \"acRate\": \"59.1%\"}",
"hints": [
"The intended solution uses Dynamic Programming.",
"Let <code>dp[i]</code> denote the minimum number of coins, such that we bought <code>i<sup>th</sup></code> fruit and acquired all the fruits in the range <code>[i...n]</code>.",

File diff suppressed because one or more lines are too long

View File

@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"5.1K\", \"totalSubmission\": \"9.8K\", \"totalAcceptedRaw\": 5143, \"totalSubmissionRaw\": 9788, \"acRate\": \"52.5%\"}",
"stats": "{\"totalAccepted\": \"5.4K\", \"totalSubmission\": \"10.1K\", \"totalAcceptedRaw\": 5371, \"totalSubmissionRaw\": 10104, \"acRate\": \"53.2%\"}",
"hints": [
"Every <code>1</code> in the string <code>s</code> should be swapped with every <code>0</code> on its right side.",
"Iterate right to left and count the number of <code>0</code> that have already occurred, whenever you iterate on <code>1</code> add that counter to the answer."

View File

@ -4,7 +4,7 @@
<p>返回执行任意次操作后能得到的 <strong>字典序最小的数组</strong><em> </em></p>
<p>如果在数组 <code>a</code> 和数组 <code>b</code> 第一个不同的位置上,数组 <code>a</code> 中的对应字符比数组 <code>b</code> 中的对应字符的字典序更小,则认为数组 <code>a</code> 就比数组 <code>b</code> 字典序更小。例如,数组 <code>[2,10,3]</code> 比数组 <code>[10,2,3]</code> 字典序更小,下标 <code>0</code> 处是两个数组第一个不同的位置,且 <code>2 &lt; 10</code></p>
<p>如果在数组 <code>a</code> 和数组 <code>b</code> 第一个不同的位置上,数组 <code>a</code> 中的对应元素比数组 <code>b</code> 中的对应元素的字典序更小,则认为数组 <code>a</code> 就比数组 <code>b</code> 字典序更小。例如,数组 <code>[2,10,3]</code> 比数组 <code>[10,2,3]</code> 字典序更小,下标 <code>0</code> 处是两个数组第一个不同的位置,且 <code>2 &lt; 10</code></p>
<p>&nbsp;</p>

View File

@ -1,4 +1,4 @@
<p>给你一个大小为 <code>m x n</code> 的整数矩阵 <code>mat</code> 和一个整数 <code>k</code> 。请你将矩阵中的<strong> 奇数</strong> 行循环 <strong></strong><code>k</code> 次,<strong>偶数</strong> 行循环 <strong></strong><code>k</code> 次。</p>
<p>给你一个<strong>下标从 0 开始</strong>大小为 <code>m x n</code> 的整数矩阵 <code>mat</code> 和一个整数 <code>k</code> 。请你将矩阵中的<strong> 奇数</strong> 行循环 <strong></strong><code>k</code> 次,<strong>偶数</strong> 行循环 <strong></strong><code>k</code> 次。</p>
<p>如果初始矩阵和最终矩阵完全相同,则返回 <code>true</code> ,否则返回 <code>false</code></p>

View File

@ -0,0 +1,42 @@
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>mountain</code> 。你的任务是找出数组&nbsp;<code>mountain</code> 中的所有 <strong>峰值</strong></p>
<p>以数组形式返回给定数组中 <strong>峰值</strong> 的下标,<strong>顺序不限</strong></p>
<p><strong>注意:</strong></p>
<ul>
<li><strong>峰值</strong> 是指一个严格大于其相邻元素的元素。</li>
<li>数组的第一个和最后一个元素 <strong></strong> 是峰值。</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>mountain = [2,4,4]
<strong>输出:</strong>[]
<strong>解释:</strong>mountain[0] 和 mountain[2] 不可能是峰值,因为它们是数组的第一个和最后一个元素。
mountain[1] 也不可能是峰值,因为它不严格大于 mountain[2] 。
因此,答案为 [] 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>mountain = [1,4,3,8,5]
<strong>输出:</strong>[1,3]
<strong>解释:</strong>mountain[0] 和 mountain[4] 不可能是峰值,因为它们是数组的第一个和最后一个元素。
mountain[2] 也不可能是峰值,因为它不严格大于 mountain[3] 和 mountain[1] 。
但是 mountain[1] 和 mountain[3] 严格大于它们的相邻元素。
因此,答案是 [1,3] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= mountain.length &lt;= 100</code></li>
<li><code>1 &lt;= mountain[i] &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,40 @@
<p>给你一个字符串&nbsp;<code>word</code>&nbsp;和一个整数 <code>k</code>&nbsp;</p>
<p>如果&nbsp;<code>word</code>&nbsp;的一个子字符串 <code>s</code>&nbsp;满足以下条件,我们称它是 <strong>完全字符串:</strong></p>
<ul>
<li><code>s</code>&nbsp;中每个字符 <strong>恰好</strong>&nbsp;出现 <code>k</code>&nbsp;次。</li>
<li>相邻字符在字母表中的顺序 <strong>至多</strong>&nbsp;相差&nbsp;<code>2</code>&nbsp;。也就是说,<code>s</code>&nbsp;中两个相邻字符&nbsp;<code>c1</code>&nbsp;<code>c2</code>&nbsp;,它们在字母表中的位置相差<strong>&nbsp;至多</strong>&nbsp;<code>2</code></li>
</ul>
<p>请你返回 <code>word</code>&nbsp;<strong>完全</strong>&nbsp;子字符串的数目。</p>
<p><strong>子字符串</strong>&nbsp;指的是一个字符串中一段连续 <strong>非空</strong>&nbsp;的字符序列。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>word = "igigee", k = 2
<b>输出:</b>3
<b>解释:</b>完全子字符串需要满足每个字符恰好出现 2 次,且相邻字符相差至多为 2 <em><strong>igig</strong></em>ee, igig<strong style="font-style: italic;">ee</strong>, <em><strong>igigee</strong>&nbsp;</em>
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>word = "aaabbbccc", k = 3
<b>输出:</b>6
<b>解释:</b>完全子字符串需要满足每个字符恰好出现 3 次,且相邻字符相差至多为 2 <em><strong>aaa</strong></em>bbbccc, aaa<em><strong>bbb</strong></em>ccc, aaabbb<em><strong>ccc</strong></em>, <em><strong>aaabbb</strong></em>ccc, aaa<em><strong>bbbccc</strong></em>, <em><strong>aaabbbccc </strong></em>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 10<sup>5</sup></code></li>
<li><code>word</code>&nbsp;只包含小写英文字母。</li>
<li><code>1 &lt;= k &lt;= word.length</code></li>
</ul>

View File

@ -0,0 +1,49 @@
<p>给你一个整数&nbsp;<code>n</code>&nbsp;和一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>sick</code>&nbsp;,数组按 <strong>升序</strong>&nbsp;排序。</p>
<p>&nbsp;<code>n</code>&nbsp;位小朋友站成一排,按顺序编号为 <code>0</code>&nbsp;<code>n - 1</code>&nbsp;。数组&nbsp;<code>sick</code>&nbsp;包含一开始得了感冒的小朋友的位置。如果位置为&nbsp;<code>i</code>&nbsp;的小朋友得了感冒,他会传染给下标为 <code>i - 1</code>&nbsp;或者 <code>i + 1</code>&nbsp;的小朋友,<strong>前提</strong> 是被传染的小朋友存在且还没有得感冒。每一秒中, <strong>至多一位</strong>&nbsp;还没感冒的小朋友会被传染。</p>
<p>经过有限的秒数后,队列中所有小朋友都会感冒。<strong>感冒序列</strong>&nbsp;指的是 <strong>所有</strong>&nbsp;一开始没有感冒的小朋友最后得感冒的顺序序列。请你返回所有感冒序列的数目。</p>
<p>由于答案可能很大,请你将答案对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;取余后返回。</p>
<p><b>注意</b>,感冒序列 <strong></strong> 包含一开始就得了感冒的小朋友的下标。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>n = 5, sick = [0,4]
<b>输出:</b>4
<b>解释:</b>一开始,下标为 1 2 和 3 的小朋友没有感冒。总共有 4 个可能的感冒序列:
- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着有感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。
然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 2 的小朋友被传染。
最后,下标为 3 的小朋友被传染,因为他挨着感冒的小朋友 2 和 4 ,感冒序列为 [1,2,3] 。
- 一开始,下标为 1 和 3 的小朋友可以被传染,因为他们分别挨着感冒的小朋友 0 和 4 ,令下标为 1 的小朋友先被传染。
然后,下标为 2 的小朋友挨着感冒的小朋友 1 ,下标为 3 的小朋友挨着感冒的小朋友 4 ,两位小朋友都可以被传染,令下标为 3 的小朋友被传染。
最后,下标为 2 的小朋友被传染,因为他挨着感冒的小朋友 1 和 3 ,感冒序列为 [1,3,2] 。
- 感冒序列 [3,1,2] ,被传染的顺序:[<strong><em>0</em></strong>,1,2,3,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,1,2,<strong><em>3</em></strong>,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,2,<em><strong>3</strong></em>,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>,<strong><em>4</em></strong>] 。
- 感冒序列 [3,2,1] ,被传染的顺序:[<strong><em>0</em></strong>,1,2,3,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,1,2,<strong><em>3</em></strong>,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,1,<strong><em>2</em></strong>,<strong><em>3</em></strong>,<strong><em>4</em></strong>] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>,<strong><em>4</em></strong>] 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>n = 4, sick = [1]
<b>输出:</b>3
<b>解释:</b>一开始,下标为 0 2 和 3 的小朋友没有感冒。总共有 3 个可能的感冒序列:
- 感冒序列 [0,2,3] ,被传染的顺序:[0,<strong><em>1</em></strong>,2,3] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,2,3] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,3] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>] 。
- 感冒序列 [2,0,3] ,被传染的顺序:[0,<strong><em>1</em></strong>,2,3] =&gt; [0,<strong><em>1</em></strong>,<strong><em>2</em></strong>,3] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,3] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>] 。
- 感冒序列 [2,3,0] ,被传染的顺序:[0,<strong><em>1</em></strong>,2,3] =&gt; [0,<strong><em>1</em></strong>,<strong><em>2</em></strong>,3] =&gt; [0,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>] =&gt; [<strong><em>0</em></strong>,<strong><em>1</em></strong>,<strong><em>2</em></strong>,<strong><em>3</em></strong>] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= sick.length &lt;= n - 1</code></li>
<li><code>0 &lt;= sick[i] &lt;= n - 1</code></li>
<li><code>sick</code>&nbsp;按升序排列。</li>
</ul>

View File

@ -0,0 +1,45 @@
<p>给你一个下标从 <strong>0 </strong>开始的整数数组 <code>coins</code>,表示可用的硬币的面值,以及一个整数 <code>target</code></p>
<p>如果存在某个 <code>coins</code> 的子序列总和为 <code>x</code>,那么整数 <code>x</code> 就是一个 <strong>可取得的金额 </strong></p>
<p>返回需要添加到数组中的<strong> 任意面值 </strong>硬币的 <strong>最小数量 </strong>,使范围 <code>[1, target]</code> 内的每个整数都属于 <strong>可取得的金额</strong></p>
<p>数组的 <strong>子序列</strong> 是通过删除原始数组的一些(<strong>可能不删除</strong>)元素而形成的新的 <strong>非空</strong> 数组,删除过程不会改变剩余元素的相对位置。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>coins = [1,4,10], target = 19
<strong>输出:</strong>2
<strong>解释:</strong>需要添加面值为 2 和 8 的硬币各一枚,得到硬币数组 [1,2,4,8,10] 。
可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 2 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>coins = [1,4,10,5,7,19], target = 19
<strong>输出:</strong>1
<strong>解释:</strong>只需要添加一枚面值为 2 的硬币,得到硬币数组 [1,2,4,5,7,10,19] 。
可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 1 。</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>coins = [1,1,1], target = 20
<strong>输出:</strong>3
<strong>解释:</strong>
需要添加面值为 4 、8 和 16 的硬币各一枚,得到硬币数组 [1,1,1,4,8,16] 。
可以证明从 1 到 20 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 3 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins[i] &lt;= target</code></li>
</ul>

View File

@ -0,0 +1,40 @@
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p>
<p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given array in <strong>any order</strong>.</em></p>
<p><strong>Notes:</strong></p>
<ul>
<li>A <strong>peak</strong> is defined as an element that is <strong>strictly greater</strong> than its neighboring elements.</li>
<li>The first and last elements of the array are <strong>not</strong> a peak.</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> mountain = [2,4,4]
<strong>Output:</strong> []
<strong>Explanation:</strong> mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
So the answer is [].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> mountain = [1,4,3,8,5]
<strong>Output:</strong> [1,3]
<strong>Explanation:</strong> mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
But mountain [1] and mountain[3] are strictly greater than their neighboring elements.
So the answer is [1,3].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= mountain.length &lt;= 100</code></li>
<li><code>1 &lt;= mountain[i] &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,38 @@
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p>
<p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p>
<ul>
<li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li>
<li>The difference between two adjacent characters is <strong>at most</strong> <code>2</code>. That is, for any two adjacent characters <code>c1</code> and <code>c2</code> in <code>s</code>, the absolute difference in their positions in the alphabet is <strong>at most</strong> <code>2</code>.</li>
</ul>
<p>Return <em>the number of <strong>complete </strong>substrings of</em> <code>word</code>.</p>
<p>A <strong>substring</strong> is a <strong>non-empty</strong> contiguous sequence of characters in a string.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> word = &quot;igigee&quot;, k = 2
<strong>Output:</strong> 3
<strong>Explanation:</strong> The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: <u><strong>igig</strong></u>ee, igig<u><strong>ee</strong></u>, <u><strong>igigee</strong></u>.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> word = &quot;aaabbbccc&quot;, k = 3
<strong>Output:</strong> 6
<strong>Explanation:</strong> The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: <strong><u>aaa</u></strong>bbbccc, aaa<u><strong>bbb</strong></u>ccc, aaabbb<u><strong>ccc</strong></u>, <strong><u>aaabbb</u></strong>ccc, aaa<u><strong>bbbccc</strong></u>, <u><strong>aaabbbccc</strong></u>.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 10<sup>5</sup></code></li>
<li><code>word</code> consists only of lowercase English letters.</li>
<li><code>1 &lt;= k &lt;= word.length</code></li>
</ul>

View File

@ -0,0 +1,47 @@
<p>You are given an integer <code>n</code> and a <strong>0-indexed</strong><strong> </strong>integer array <code>sick</code> which is <strong>sorted</strong> in <strong>increasing</strong> order.</p>
<p>There are <code>n</code> children standing in a queue with positions <code>0</code> to <code>n - 1</code> assigned to them. The array <code>sick</code> contains the positions of the children who are infected with an infectious disease. An infected child at position <code>i</code> can spread the disease to either of its immediate neighboring children at positions <code>i - 1</code> and <code>i + 1</code> <strong>if</strong> they exist and are currently not infected. <strong>At most one</strong> child who was previously not infected can get infected with the disease in one second.</p>
<p>It can be shown that after a finite number of seconds, all the children in the queue will get infected with the disease. An <strong>infection sequence</strong> is the sequential order of positions in which <strong>all</strong> of the non-infected children get infected with the disease. Return <em>the total number of possible infection sequences</em>.</p>
<p>Since the answer may be large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Note</strong> that an infection sequence <strong>does not</strong> contain positions of children who were already infected with the disease in the beginning.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> n = 5, sick = [0,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> Children at positions 1, 2, and 3 are not infected in the beginning. There are 4 possible infection sequences:
- The children at positions 1 and 3 can get infected since their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 2 gets infected.
Finally, the child at position 3 gets infected because it is adjacent to children at positions 2 and 4 who are infected. The infection sequence is [1,2,3].
- The children at positions 1 and 3 can get infected because their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 3 gets infected.
Finally, the child at position 2 gets infected because it is adjacent to children at positions 1 and 3 who are infected. The infection sequence is [1,3,2].
- The infection sequence is [3,1,2]. The order of infection of disease in the children can be seen as: [<u>0</u>,1,2,3,<u>4</u>] =&gt; [<u>0</u>,1,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>].
- The infection sequence is [3,2,1]. The order of infection of disease in the children can be seen as: [<u>0</u>,1,2,3,<u>4</u>] =&gt; [<u>0</u>,1,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,1,<u>2</u>,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> n = 4, sick = [1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Children at positions 0, 2, and 3 are not infected in the beginning. There are 3 possible infection sequences:
- The infection sequence is [0,2,3]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [<u>0</u>,<u>1</u>,2,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
- The infection sequence is [2,0,3]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [0,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
- The infection sequence is [2,3,0]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [0,<u>1</u>,<u>2</u>,3] =&gt; [0,<u>1</u>,<u>2</u>,<u>3</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= sick.length &lt;= n - 1</code></li>
<li><code>0 &lt;= sick[i] &lt;= n - 1</code></li>
<li><code>sick</code> is sorted in increasing order.</li>
</ul>

View File

@ -0,0 +1,44 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p>
<p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p>
<p>Return <em>the<strong> minimum</strong> number of coins <strong>of any value</strong> that need to be added to the array so that every integer in the range</em> <code>[1, target]</code><em> is <strong>obtainable</strong></em>.</p>
<p>A <strong>subsequence</strong> of an array is a new <strong>non-empty</strong> array that is formed from the original array by deleting some (<strong>possibly none</strong>) of the elements without disturbing the relative positions of the remaining elements.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,4,10], target = 19
<strong>Output:</strong> 2
<strong>Explanation:</strong> We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,4,10,5,7,19], target = 19
<strong>Output:</strong> 1
<strong>Explanation:</strong> We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,1,1], target = 20
<strong>Output:</strong> 3
<strong>Explanation:</strong> We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].
It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins[i] &lt;= target</code></li>
</ul>

File diff suppressed because it is too large Load Diff

View File

@ -11,17 +11,42 @@
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Hard",
"likes": 8,
"likes": 10,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[2,1,4,4,4,2]\n2\n[7,3,9,4]\n1",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Number Theory",
"slug": "number-theory",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"188\", \"totalSubmission\": \"390\", \"totalAcceptedRaw\": 188, \"totalSubmissionRaw\": 390, \"acRate\": \"48.2%\"}",
"stats": "{\"totalAccepted\": \"240\", \"totalSubmission\": \"472\", \"totalAcceptedRaw\": 240, \"totalSubmissionRaw\": 472, \"acRate\": \"50.8%\"}",
"hints": [
"Try to answer the query of asking GCD of a subarray in <code>O(1)</code> using sparse tables and preprocessing.",
"For every index <code>L</code>, lets find the subarray starting at the index <code>L</code> and maximizing gcd-sum.",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,14 +11,33 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 39,
"dislikes": 2,
"likes": 89,
"dislikes": 6,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "\"baeyh\"\n2\n\"abba\"\n1\n\"bcdf\"\n1",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "String",
"slug": "string",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Enumeration",
"slug": "enumeration",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"10.6K\", \"totalSubmission\": \"17.8K\", \"totalAcceptedRaw\": 10627, \"totalSubmissionRaw\": 17779, \"acRate\": \"59.8%\"}",
"stats": "{\"totalAccepted\": \"14.8K\", \"totalSubmission\": \"24.1K\", \"totalAcceptedRaw\": 14772, \"totalSubmissionRaw\": 24125, \"acRate\": \"61.2%\"}",
"hints": [
"Iterate over all substrings and maintain the frequencies of vowels and consonants."
],

View File

@ -11,14 +11,45 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 56,
"likes": 123,
"dislikes": 3,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "\"baeyh\"\n2\n\"abba\"\n1\n\"bcdf\"\n1",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "String",
"slug": "string",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Number Theory",
"slug": "number-theory",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +167,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.7K\", \"totalSubmission\": \"9.4K\", \"totalAcceptedRaw\": 1722, \"totalSubmissionRaw\": 9413, \"acRate\": \"18.3%\"}",
"stats": "{\"totalAccepted\": \"3.3K\", \"totalSubmission\": \"14.1K\", \"totalAcceptedRaw\": 3335, \"totalSubmissionRaw\": 14063, \"acRate\": \"23.7%\"}",
"hints": [
"For the given <code>k</code> find all the <code>x</code> integers such that <code>x^2 % k == 0</code>. Notice, that there arent many such candidates.",
"We can iterate over all such <code>x</codes> values and count the number of substrings such that <code>vowels == consonants == x</code>.",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,8 +11,8 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 148,
"dislikes": 1,
"likes": 160,
"dislikes": 2,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Number of Visible People in a Queue\", \"titleSlug\": \"number-of-visible-people-in-a-queue\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Furthest Building You Can Reach\", \"titleSlug\": \"furthest-building-you-can-reach\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "[6,4,8,5,2,7]\n[[0,1],[0,3],[2,4],[3,4],[2,2]]\n[5,3,8,2,6,1,4,6]\n[[0,7],[3,5],[5,2],[3,0],[1,6]]",
@ -179,7 +179,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"4.1K\", \"totalSubmission\": \"12.8K\", \"totalAcceptedRaw\": 4108, \"totalSubmissionRaw\": 12790, \"acRate\": \"32.1%\"}",
"stats": "{\"totalAccepted\": \"4.6K\", \"totalSubmission\": \"13.8K\", \"totalAcceptedRaw\": 4574, \"totalSubmissionRaw\": 13821, \"acRate\": \"33.1%\"}",
"hints": [
"For each query <code>[x, y]</code>, if <code>x > y</code>, swap <code>x</code> and <code>y</code>. Now, we can assume that <code>x <= y</code>.",
"For each query <code>[x, y]</code>, if <code>x == y</code> or <code>heights[x] < heights[y]</code>, then the answer is <code>y</code> since <code>x ≤ y</code>.",

View File

@ -11,14 +11,57 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 45,
"dislikes": 5,
"likes": 77,
"dislikes": 8,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[5,2,2]\n[1,2,3,4]\n[4,3,2,6]",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Stack",
"slug": "stack",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Queue",
"slug": "queue",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Stack",
"slug": "monotonic-stack",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Queue",
"slug": "monotonic-queue",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +179,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"571\", \"totalSubmission\": \"6.5K\", \"totalAcceptedRaw\": 571, \"totalSubmissionRaw\": 6546, \"acRate\": \"8.7%\"}",
"stats": "{\"totalAccepted\": \"1.4K\", \"totalSubmission\": \"9.9K\", \"totalAcceptedRaw\": 1364, \"totalSubmissionRaw\": 9902, \"acRate\": \"13.8%\"}",
"hints": [
"Let <code>dp[i]</code> be the maximum number of elements in the increasing sequence after processing the first <code>i</code> elements of the original array.",
"We have <code>dp[0] = 0</code>. <code>dp[i + 1] >= dp[i]</code> (since if we have the solution for the first <code>i</code> elements, we can always merge the last one of the first <code>i + 1</code> elements which is <code>nums[i]</code> into the solution of the first <code>i</code> elements.",

File diff suppressed because one or more lines are too long

View File

@ -11,14 +11,27 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 34,
"dislikes": 1,
"likes": 91,
"dislikes": 3,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Find Target Indices After Sorting Array\", \"titleSlug\": \"find-target-indices-after-sorting-array\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"exampleTestcases": "[\"leet\",\"code\"]\n\"e\"\n[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"a\"\n[\"abc\",\"bcd\",\"aaaa\",\"cbc\"]\n\"z\"",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "String",
"slug": "string",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"15.8K\", \"totalSubmission\": \"17.5K\", \"totalAcceptedRaw\": 15750, \"totalSubmissionRaw\": 17499, \"acRate\": \"90.0%\"}",
"stats": "{\"totalAccepted\": \"27.9K\", \"totalSubmission\": \"31.6K\", \"totalAcceptedRaw\": 27917, \"totalSubmissionRaw\": 31551, \"acRate\": \"88.5%\"}",
"hints": [
"Use two nested loops."
],

View File

@ -11,14 +11,33 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 90,
"dislikes": 8,
"likes": 176,
"dislikes": 9,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Smallest String With Swaps\", \"titleSlug\": \"smallest-string-with-swaps\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Minimize Hamming Distance After Swap Operations\", \"titleSlug\": \"minimize-hamming-distance-after-swap-operations\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "[1,5,3,9,8]\n2\n[1,7,6,18,2,1]\n3\n[1,7,28,19,10]\n3",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Union Find",
"slug": "union-find",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Sorting",
"slug": "sorting",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"3.5K\", \"totalSubmission\": \"11.8K\", \"totalAcceptedRaw\": 3528, \"totalSubmissionRaw\": 11769, \"acRate\": \"30.0%\"}",
"stats": "{\"totalAccepted\": \"6.2K\", \"totalSubmission\": \"16.9K\", \"totalAcceptedRaw\": 6212, \"totalSubmissionRaw\": 16936, \"acRate\": \"36.7%\"}",
"hints": [
"Construct a virtual graph where all elements in <code>nums</code> are nodes and the pairs satisfying the condition have an edge between them.",
"Instead of constructing all edges, we only care about the connected components.",

View File

@ -11,7 +11,7 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 87,
"likes": 103,
"dislikes": 27,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Delete Operation for Two Strings\", \"titleSlug\": \"delete-operation-for-two-strings\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
@ -143,7 +143,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"17.8K\", \"totalSubmission\": \"44.1K\", \"totalAcceptedRaw\": 17821, \"totalSubmissionRaw\": 44052, \"acRate\": \"40.5%\"}",
"stats": "{\"totalAccepted\": \"19K\", \"totalSubmission\": \"46.7K\", \"totalAcceptedRaw\": 19038, \"totalSubmissionRaw\": 46709, \"acRate\": \"40.8%\"}",
"hints": [
"Calculate the length of the longest common prefix of the <code>3</code> strings."
],

View File

@ -11,14 +11,39 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 25,
"dislikes": 24,
"likes": 58,
"dislikes": 40,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[[1,2,1,2],[5,5,5,5],[6,3,6,3]]\n2\n[[2,2],[2,2]]\n3\n[[1,2]]\n1",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Math",
"slug": "math",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Matrix",
"slug": "matrix",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Simulation",
"slug": "simulation",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"11.8K\", \"totalSubmission\": \"21.7K\", \"totalAcceptedRaw\": 11795, \"totalSubmissionRaw\": 21672, \"acRate\": \"54.4%\"}",
"stats": "{\"totalAccepted\": \"16.6K\", \"totalSubmission\": \"29.4K\", \"totalAcceptedRaw\": 16608, \"totalSubmissionRaw\": 29371, \"acRate\": \"56.5%\"}",
"hints": [
"You can reduce <code>k</code> shifts to <code>(k % n)</code> shifts as after <code>n</code> shifts the matrix will become similar to the initial matrix."
],

View File

@ -11,14 +11,27 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 43,
"dislikes": 77,
"likes": 65,
"dislikes": 98,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Maximal Square\", \"titleSlug\": \"maximal-square\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "2\n1\n[2,3]\n[2]\n1\n1\n[2]\n[2]\n2\n3\n[2,3]\n[2,3,4]",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Sorting",
"slug": "sorting",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"6.8K\", \"totalSubmission\": \"21.2K\", \"totalAcceptedRaw\": 6789, \"totalSubmissionRaw\": 21211, \"acRate\": \"32.0%\"}",
"stats": "{\"totalAccepted\": \"8.3K\", \"totalSubmission\": \"24.6K\", \"totalAcceptedRaw\": 8326, \"totalSubmissionRaw\": 24583, \"acRate\": \"33.9%\"}",
"hints": [
"Sort <code>hBars</code> and <code>vBars</code> and consider them separately.",
"Compute the longest sequence of consecutive integer values in each array, denoted as <code>[hx, hy]</code> and <code>[vx, vy]</code>, respectively.",

View File

@ -11,8 +11,8 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 123,
"dislikes": 61,
"likes": 135,
"dislikes": 63,
"isLiked": null,
"similarQuestions": "[{\"title\": \"Maximum XOR After Operations \", \"titleSlug\": \"maximum-xor-after-operations\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "12\n5\n4\n6\n7\n5\n1\n6\n3",
@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"5.7K\", \"totalSubmission\": \"24.8K\", \"totalAcceptedRaw\": 5708, \"totalSubmissionRaw\": 24784, \"acRate\": \"23.0%\"}",
"stats": "{\"totalAccepted\": \"6.1K\", \"totalSubmission\": \"26.2K\", \"totalAcceptedRaw\": 6139, \"totalSubmissionRaw\": 26184, \"acRate\": \"23.4%\"}",
"hints": [
"Iterate over bits from most significant to least significant.",
"For the <code>i<sup>th</sup></code> bit, if both <code>a</code> and <code>b</code> have the same value, we can always make <code>x</code>s <code>i<sup>th</sup></code> bit different from <code>a</code> and <code>b</code>, so <code>a ^ x</code> and <code>b ^ x</code> both have the <code>i<sup>th</sup></cod> bit set.",

View File

@ -11,14 +11,39 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 73,
"dislikes": 21,
"likes": 126,
"dislikes": 26,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[3,1,2]\n[1,10,1,1]",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Queue",
"slug": "queue",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Monotonic Queue",
"slug": "monotonic-queue",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
@ -136,7 +161,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"7.2K\", \"totalSubmission\": \"18.3K\", \"totalAcceptedRaw\": 7194, \"totalSubmissionRaw\": 18336, \"acRate\": \"39.2%\"}",
"stats": "{\"totalAccepted\": \"9.5K\", \"totalSubmission\": \"22.6K\", \"totalAcceptedRaw\": 9522, \"totalSubmissionRaw\": 22589, \"acRate\": \"42.2%\"}",
"hints": [
"The intended solution uses Dynamic Programming.",
"Let <code>dp[i]</code> denote the minimum number of coins, such that we bought <code>i<sup>th</sup></code> fruit and acquired all the fruits in the range <code>[i...n]</code>.",

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 116,
"likes": 128,
"dislikes": 2,
"isLiked": null,
"similarQuestions": "[]",
@ -155,7 +155,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"16.5K\", \"totalSubmission\": \"32K\", \"totalAcceptedRaw\": 16488, \"totalSubmissionRaw\": 32046, \"acRate\": \"51.5%\"}",
"stats": "{\"totalAccepted\": \"17.4K\", \"totalSubmission\": \"33.7K\", \"totalAcceptedRaw\": 17401, \"totalSubmissionRaw\": 33710, \"acRate\": \"51.6%\"}",
"hints": [
"Every <code>1</code> in the string <code>s</code> should be swapped with every <code>0</code> on its right side.",
"Iterate right to left and count the number of <code>0</code> that have already occurred, whenever you iterate on <code>1</code> add that counter to the answer."

View File

@ -0,0 +1,38 @@
<p>You are given a string <code>word</code> and an integer <code>k</code>.</p>
<p>A substring <code>s</code> of <code>word</code> is <strong>complete</strong> if:</p>
<ul>
<li>Each character in <code>s</code> occurs <strong>exactly</strong> <code>k</code> times.</li>
<li>The difference between two adjacent characters is <strong>at most</strong> <code>2</code>. That is, for any two adjacent characters <code>c1</code> and <code>c2</code> in <code>s</code>, the absolute difference in their positions in the alphabet is <strong>at most</strong> <code>2</code>.</li>
</ul>
<p>Return <em>the number of <strong>complete </strong>substrings of</em> <code>word</code>.</p>
<p>A <strong>substring</strong> is a <strong>non-empty</strong> contiguous sequence of characters in a string.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> word = &quot;igigee&quot;, k = 2
<strong>Output:</strong> 3
<strong>Explanation:</strong> The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: <u><strong>igig</strong></u>ee, igig<u><strong>ee</strong></u>, <u><strong>igigee</strong></u>.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> word = &quot;aaabbbccc&quot;, k = 3
<strong>Output:</strong> 6
<strong>Explanation:</strong> The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: <strong><u>aaa</u></strong>bbbccc, aaa<u><strong>bbb</strong></u>ccc, aaabbb<u><strong>ccc</strong></u>, <strong><u>aaabbb</u></strong>ccc, aaa<u><strong>bbbccc</strong></u>, <u><strong>aaabbbccc</strong></u>.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= word.length &lt;= 10<sup>5</sup></code></li>
<li><code>word</code> consists only of lowercase English letters.</li>
<li><code>1 &lt;= k &lt;= word.length</code></li>
</ul>

View File

@ -0,0 +1,47 @@
<p>You are given an integer <code>n</code> and a <strong>0-indexed</strong><strong> </strong>integer array <code>sick</code> which is <strong>sorted</strong> in <strong>increasing</strong> order.</p>
<p>There are <code>n</code> children standing in a queue with positions <code>0</code> to <code>n - 1</code> assigned to them. The array <code>sick</code> contains the positions of the children who are infected with an infectious disease. An infected child at position <code>i</code> can spread the disease to either of its immediate neighboring children at positions <code>i - 1</code> and <code>i + 1</code> <strong>if</strong> they exist and are currently not infected. <strong>At most one</strong> child who was previously not infected can get infected with the disease in one second.</p>
<p>It can be shown that after a finite number of seconds, all the children in the queue will get infected with the disease. An <strong>infection sequence</strong> is the sequential order of positions in which <strong>all</strong> of the non-infected children get infected with the disease. Return <em>the total number of possible infection sequences</em>.</p>
<p>Since the answer may be large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
<p><strong>Note</strong> that an infection sequence <strong>does not</strong> contain positions of children who were already infected with the disease in the beginning.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> n = 5, sick = [0,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> Children at positions 1, 2, and 3 are not infected in the beginning. There are 4 possible infection sequences:
- The children at positions 1 and 3 can get infected since their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 2 gets infected.
Finally, the child at position 3 gets infected because it is adjacent to children at positions 2 and 4 who are infected. The infection sequence is [1,2,3].
- The children at positions 1 and 3 can get infected because their positions are adjacent to the infected children 0 and 4. The child at position 1 gets infected first.
Now, the child at position 2 is adjacent to the child at position 1 who is infected and the child at position 3 is adjacent to the child at position 4 who is infected, hence either of them can get infected. The child at position 3 gets infected.
Finally, the child at position 2 gets infected because it is adjacent to children at positions 1 and 3 who are infected. The infection sequence is [1,3,2].
- The infection sequence is [3,1,2]. The order of infection of disease in the children can be seen as: [<u>0</u>,1,2,3,<u>4</u>] =&gt; [<u>0</u>,1,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>].
- The infection sequence is [3,2,1]. The order of infection of disease in the children can be seen as: [<u>0</u>,1,2,3,<u>4</u>] =&gt; [<u>0</u>,1,2,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,1,<u>2</u>,<u>3</u>,<u>4</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> n = 4, sick = [1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Children at positions 0, 2, and 3 are not infected in the beginning. There are 3 possible infection sequences:
- The infection sequence is [0,2,3]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [<u>0</u>,<u>1</u>,2,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
- The infection sequence is [2,0,3]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [0,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,3] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
- The infection sequence is [2,3,0]. The order of infection of disease in the children can be seen as: [0,<u>1</u>,2,3] =&gt; [0,<u>1</u>,<u>2</u>,3] =&gt; [0,<u>1</u>,<u>2</u>,<u>3</u>] =&gt; [<u>0</u>,<u>1</u>,<u>2</u>,<u>3</u>].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= sick.length &lt;= n - 1</code></li>
<li><code>0 &lt;= sick[i] &lt;= n - 1</code></li>
<li><code>sick</code> is sorted in increasing order.</li>
</ul>

View File

@ -0,0 +1,40 @@
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p>
<p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given array in <strong>any order</strong>.</em></p>
<p><strong>Notes:</strong></p>
<ul>
<li>A <strong>peak</strong> is defined as an element that is <strong>strictly greater</strong> than its neighboring elements.</li>
<li>The first and last elements of the array are <strong>not</strong> a peak.</li>
</ul>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> mountain = [2,4,4]
<strong>Output:</strong> []
<strong>Explanation:</strong> mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
So the answer is [].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> mountain = [1,4,3,8,5]
<strong>Output:</strong> [1,3]
<strong>Explanation:</strong> mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
But mountain [1] and mountain[3] are strictly greater than their neighboring elements.
So the answer is [1,3].
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 &lt;= mountain.length &lt;= 100</code></li>
<li><code>1 &lt;= mountain[i] &lt;= 100</code></li>
</ul>

View File

@ -0,0 +1,44 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p>
<p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p>
<p>Return <em>the<strong> minimum</strong> number of coins <strong>of any value</strong> that need to be added to the array so that every integer in the range</em> <code>[1, target]</code><em> is <strong>obtainable</strong></em>.</p>
<p>A <strong>subsequence</strong> of an array is a new <strong>non-empty</strong> array that is formed from the original array by deleting some (<strong>possibly none</strong>) of the elements without disturbing the relative positions of the remaining elements.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,4,10], target = 19
<strong>Output:</strong> 2
<strong>Explanation:</strong> We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,4,10,5,7,19], target = 19
<strong>Output:</strong> 1
<strong>Explanation:</strong> We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> coins = [1,1,1], target = 20
<strong>Output:</strong> 3
<strong>Explanation:</strong> We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].
It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= coins[i] &lt;= target</code></li>
</ul>