1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-04-18 08:39:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
zhangbk1 2024-03-28 09:27:27 +08:00
parent 0bbe66ecc9
commit 26ccf4c890
15 changed files with 9528 additions and 8170 deletions

File diff suppressed because it is too large Load Diff

@ -0,0 +1,62 @@
{
"data": {
"question": {
"questionId": "3400",
"questionFrontendId": "3089",
"categoryTitle": "Database",
"boundTopicId": 2704231,
"title": "Find Bursty Behavior",
"titleSlug": "find-bursty-behavior",
"content": null,
"translatedTitle": "查找突发行为",
"translatedContent": null,
"isPaidOnly": true,
"difficulty": "Medium",
"likes": 0,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": null,
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": null,
"stats": "{\"totalAccepted\": \"25\", \"totalSubmission\": \"62\", \"totalAcceptedRaw\": 25, \"totalSubmissionRaw\": 62, \"acRate\": \"40.3%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Posts\": [\"post_id\", \"user_id\", \"post_date\"]}, \"rows\": {\"Posts\": [[1, 1, \"2024-02-27\"], [2, 5, \"2024-02-06\"], [3, 3, \"2024-02-25\"], [4, 3, \"2024-02-14\"], [5, 3, \"2024-02-06\"], [6, 2, \"2024-02-25\"]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Posts (post_id int, user_id int, post_date date)\"],\"mssql\":[\"Create table Posts (post_id int, user_id int, post_date date)\"],\"oraclesql\":[\"Create table Posts (post_id int, user_id int, post_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"find_bursty_behavior\",\"pythondata\":[\"Posts = pd.DataFrame([], columns=['post_id', 'user_id', 'post_date']).astype({'post_id':'Int64', 'user_id':'Int64', 'post_date':'datetime64[ns]'})\\n\"],\"postgresql\":[\"CREATE TABLE Posts (\\n post_id int,\\n user_id int,\\n post_date date\\n);\\n\",\"SELECT TO_CHAR(post_date, 'YYYY-MM-DD') AS formatted_post_date FROM Posts;\\n\"],\"database_schema\":{\"Posts\":{\"post_id\":\"INT\",\"user_id\":\"INT\",\"post_date\":\"DATE\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"Create table If Not Exists Posts (post_id int, user_id int, post_date date)",
"Truncate table Posts",
"insert into Posts (post_id, user_id, post_date) values ('1', '1', '2024-02-27')",
"insert into Posts (post_id, user_id, post_date) values ('2', '5', '2024-02-06')",
"insert into Posts (post_id, user_id, post_date) values ('3', '3', '2024-02-25')",
"insert into Posts (post_id, user_id, post_date) values ('4', '3', '2024-02-14')",
"insert into Posts (post_id, user_id, post_date) values ('5', '3', '2024-02-06')",
"insert into Posts (post_id, user_id, post_date) values ('6', '2', '2024-02-25')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\": {\"Posts\": [\"post_id\", \"user_id\", \"post_date\"]}, \"rows\": {\"Posts\": [[1, 1, \"2024-02-27\"], [2, 5, \"2024-02-06\"], [3, 3, \"2024-02-25\"], [4, 3, \"2024-02-14\"], [5, 3, \"2024-02-06\"], [6, 2, \"2024-02-25\"]]}}",
"__typename": "QuestionNode"
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,52 @@
<p>给你一个<strong>正整数</strong> <code>k</code> 。最初,你有一个数组 <code>nums = [1]</code></p>
<p>你可以对数组执行以下 <strong>任意 </strong>操作 <strong>任意 </strong>次数(<strong>可能为零</strong></p>
<ul>
<li>选择数组中的任何一个元素,然后将它的值<strong> 增加</strong> <code>1</code></li>
<li>复制数组中的任何一个元素,然后将它附加到数组的末尾。</li>
</ul>
<p>返回使得最终数组元素之<strong></strong>大于或等于 <code>k</code> 所需的 <strong>最少 </strong>操作次数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">k = 11</span></p>
<p><strong>输出:</strong><span class="example-io">5</span></p>
<p><strong>解释:</strong></p>
<p>可以对数组 <code>nums = [1]</code> 执行以下操作:</p>
<ul>
<li>将元素的值增加 <code>1</code> 三次。结果数组为 <code>nums = [4]</code></li>
<li>复制元素两次。结果数组为 <code>nums = [4,4,4]</code></li>
</ul>
<p>最终数组的和为 <code>4 + 4 + 4 = 12</code> ,大于等于 <code>k = 11</code><br />
执行的总操作次数为 <code>3 + 2 = 5</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong><span class="example-io">k = 1</span></p>
<p><strong>输出:</strong><span class="example-io">0</span></p>
<p><strong>解释:</strong></p>
<p>原始数组的和已经大于等于 <code>1</code> ,因此不需要执行操作。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,57 @@
<p>给你两个字符串数组&nbsp;<code>wordsContainer</code>&nbsp;<code>wordsQuery</code>&nbsp;</p>
<p>对于每个&nbsp;<code>wordsQuery[i]</code>&nbsp;,你需要从&nbsp;<code>wordsContainer</code>&nbsp;中找到一个与&nbsp;<code>wordsQuery[i]</code>&nbsp;&nbsp;<strong>最长公共后缀</strong>&nbsp;的字符串。如果 <code>wordsContainer</code>&nbsp;中有两个或者更多字符串有最长公共后缀,那么答案为长度<strong>&nbsp;最短</strong>&nbsp;的。如果有超过两个字符串有&nbsp;<strong>相同</strong>&nbsp;最短长度,那么答案为它们在&nbsp;<code>wordsContainer</code>&nbsp;中出现&nbsp;<strong>更早</strong>&nbsp;的一个。</p>
<p>请你返回一个整数数组<em>&nbsp;</em><code>ans</code>&nbsp;,其中<em>&nbsp;</em><code>ans[i]</code><em>&nbsp;</em><code>wordsContainer</code>中与&nbsp;<code>wordsQuery[i]</code>&nbsp;&nbsp;<strong>最长公共后缀</strong>&nbsp;字符串的下标。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>wordsContainer = ["abcd","bcd","xbcd"], wordsQuery = ["cd","bcd","xyz"]</span></p>
<p><span class="example-io"><b>输出:</b>[1,1,1]</span></p>
<p><strong>解释:</strong></p>
<p>我们分别来看每一个&nbsp;<code>wordsQuery[i]</code>&nbsp;</p>
<ul>
<li>对于&nbsp;<code>wordsQuery[0] = "cd"</code>&nbsp;<code>wordsContainer</code>&nbsp;中有最长公共后缀&nbsp;<code>"cd"</code>&nbsp;的字符串下标分别为&nbsp;0 1 和&nbsp;2 。这些字符串中,答案是下标为 1 的字符串,因为它的长度为 3 ,是最短的字符串。</li>
<li>对于&nbsp;<code>wordsQuery[1] = "bcd"</code>&nbsp;<code>wordsContainer</code>&nbsp;中有最长公共后缀&nbsp;<code>"bcd"</code>&nbsp;的字符串下标分别为 0 1 和 2 。这些字符串中,答案是下标为 1 的字符串,因为它的长度为 3 ,是最短的字符串。</li>
<li>对于&nbsp;<code>wordsQuery[2] = "xyz"</code>&nbsp;<code>wordsContainer</code>&nbsp;中没有字符串跟它有公共后缀,所以最长公共后缀为&nbsp;<code>""</code>&nbsp;,下标为&nbsp;0 1 和 2 的字符串都得到这一公共后缀。这些字符串中,&nbsp;答案是下标为 1 的字符串,因为它的长度为 3 ,是最短的字符串。</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>wordsContainer = ["abcdefgh","poiuygh","ghghgh"], wordsQuery = ["gh","acbfgh","acbfegh"]</span></p>
<p><span class="example-io"><b>输出:</b>[2,0,2]</span></p>
<p><strong>解释:</strong></p>
<p>我们分别来看每一个&nbsp;<code>wordsQuery[i]</code>&nbsp;</p>
<ul>
<li>对于&nbsp;<code>wordsQuery[0] = "gh"</code>&nbsp;<code>wordsContainer</code>&nbsp;中有最长公共后缀&nbsp;<code>"gh"</code>&nbsp;的字符串下标分别为 0 1 和 2 。这些字符串中,答案是下标为 2 的字符串,因为它的长度为 6 ,是最短的字符串。</li>
<li>对于&nbsp;<code>wordsQuery[1] = "acbfgh"</code>&nbsp;,只有下标为 0 的字符串有最长公共后缀&nbsp;<code>"fgh"</code>&nbsp;。所以尽管下标为 2 的字符串是最短的字符串,但答案是 0 。</li>
<li>对于&nbsp;<code>wordsQuery[2] = "acbfegh"</code>&nbsp;<code>wordsContainer</code>&nbsp;中有最长公共后缀&nbsp;<code>"gh"</code>&nbsp;的字符串下标分别为 0 1 和 2 。这些字符串中,答案是下标为 2 的字符串,因为它的长度为 6 ,是最短的字符串。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= wordsContainer.length, wordsQuery.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= wordsContainer[i].length &lt;= 5 * 10<sup>3</sup></code></li>
<li><code>1 &lt;= wordsQuery[i].length &lt;= 5 * 10<sup>3</sup></code></li>
<li><code>wordsContainer[i]</code>&nbsp;只包含小写英文字母。</li>
<li><code>wordsQuery[i]</code>&nbsp;只包含小写英文字母。</li>
<li><code>wordsContainer[i].length</code>&nbsp;的和至多为&nbsp;<code>5 * 10<sup>5</sup></code>&nbsp;</li>
<li><code>wordsQuery[i].length</code>&nbsp;的和至多为&nbsp;<code>5 * 10<sup>5</sup></code>&nbsp;</li>
</ul>

@ -0,0 +1,51 @@
<p>你需要在一个集合里动态记录 ID 的出现频率。给你两个长度都为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;<code>freq</code>&nbsp;<code>nums</code>&nbsp;中每一个元素表示一个 ID ,对应的 <code>freq</code>&nbsp;中的元素表示这个 ID 在集合中此次操作后需要增加或者减少的数目。</p>
<ul>
<li><strong>增加 ID 的数目:</strong>如果&nbsp;<code>freq[i]</code>&nbsp;是正数,那么&nbsp;<code>freq[i]</code>&nbsp;个 ID 为&nbsp;<code>nums[i]</code>&nbsp;的元素在第 <code>i</code>&nbsp;步操作后会添加到集合中。</li>
<li><strong>减少 ID 的数目:</strong>如果&nbsp;<code>freq[i]</code>&nbsp;是负数,那么&nbsp;<code>-freq[i]</code>&nbsp;个 ID 为&nbsp;<code>nums[i]</code>&nbsp;的元素在第 <code>i</code>&nbsp;步操作后会从集合中删除。</li>
</ul>
<p>请你返回一个长度为 <code>n</code>&nbsp;的数组 <code>ans</code>&nbsp;,其中&nbsp;<code>ans[i]</code>&nbsp;表示第 <code>i</code>&nbsp;步操作后出现频率最高的 ID <strong>数目</strong>&nbsp;,如果在某次操作后集合为空,那么 <code>ans[i]</code>&nbsp;为 0 。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [2,3,2,1], freq = [3,2,-3,1]</span></p>
<p><span class="example-io"><b>输出:</b>[3,3,2,2]</span></p>
<p><strong>解释:</strong></p>
<p>第 0 步操作后,有 3 个 ID 为 2 的元素,所以&nbsp;<code>ans[0] = 3</code>&nbsp;<br />
第 1 步操作后,有 3 个 ID 为 2 的元素和 2 个 ID 为 3 的元素,所以&nbsp;<code>ans[1] = 3</code>&nbsp;<br />
第 2 步操作后,有 2 个 ID 为 3 的元素,所以&nbsp;<code>ans[2] = 2</code>&nbsp;<br />
第 3 步操作后,有 2 个 ID 为 3 的元素和 1 个 ID 为 1 的元素,所以&nbsp;<code>ans[3] = 2</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [5,5,3], freq = [2,-2,1]</span></p>
<p><span class="example-io"><b>输出:</b>[2,0,1]</span></p>
<p><strong>解释:</strong></p>
<p>第 0 步操作后,有 2 个 ID 为 5 的元素,所以&nbsp;<code>ans[0] = 2</code>&nbsp;<br />
第 1 步操作后,集合中没有任何元素,所以&nbsp;<code>ans[1] = 0</code>&nbsp;<br />
第 2 步操作后,有 1 个 ID 为 3 的元素,所以&nbsp;<code>ans[2] = 1</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length == freq.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= freq[i] &lt;= 10<sup>5</sup></code></li>
<li><code>freq[i] != 0</code></li>
<li>输入保证任何操作后,集合中的元素出现次数不会为负数。</li>
</ul>

@ -0,0 +1,37 @@
<p>给你一个字符串 <code>s</code> ,请找出满足每个字符最多出现两次的最长子字符串,并返回该<span data-keyword="substring">子字符串</span><strong> 最大 </strong>长度。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "bcbbbcba"</span></p>
<p><strong>输出:</strong> <span class="example-io">4</span></p>
<p><strong>解释:</strong></p>
<p>以下子字符串长度为 4并且每个字符最多出现两次<code>"bcbb<u>bcba</u>"</code></p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "aaaa"</span></p>
<p><strong>输出:</strong> <span class="example-io">2</span></p>
<p><strong>解释:</strong></p>
<p>以下子字符串长度为 2并且每个字符最多出现两次<code>"<u>aa</u>aa"</code></p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul><!-- 字符串 s 的长度在 2 到 100 之间 -->
<li><code>2 &lt;= s.length &lt;= 100</code></li>
<!-- 字符串 s 仅包含小写英文字母 -->
<li><code>s</code> 仅由小写英文字母组成。</li>
</ul>

@ -0,0 +1,50 @@
<p>You are given a <strong>positive</strong> integer <code>k</code>. Initially, you have an array <code>nums = [1]</code>.</p>
<p>You can perform <strong>any</strong> of the following operations on the array <strong>any</strong> number of times (<strong>possibly zero</strong>):</p>
<ul>
<li>Choose any element in the array and <strong>increase</strong> its value by <code>1</code>.</li>
<li>Duplicate any element in the array and add it to the end of the array.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> number of operations required to make the <strong>sum</strong> of elements of the final array greater than or equal to </em><code>k</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 11</span></p>
<p><strong>Output:</strong> <span class="example-io">5</span></p>
<p><strong>Explanation:</strong></p>
<p>We can do the following operations on the array <code>nums = [1]</code>:</p>
<ul>
<li>Increase the element by <code>1</code> three times. The resulting array is <code>nums = [4]</code>.</li>
<li>Duplicate the element two times. The resulting array is <code>nums = [4,4,4]</code>.</li>
</ul>
<p>The sum of the final array is <code>4 + 4 + 4 = 12</code> which is greater than or equal to <code>k = 11</code>.<br />
The total number of operations performed is <code>3 + 2 = 5</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">k = 1</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>The sum of the original array is already greater than or equal to <code>1</code>, so no operations are needed.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,55 @@
<p>You are given two arrays of strings <code>wordsContainer</code> and <code>wordsQuery</code>.</p>
<p>For each <code>wordsQuery[i]</code>, you need to find a string from <code>wordsContainer</code> that has the <strong>longest common suffix</strong> with <code>wordsQuery[i]</code>. If there are two or more strings in <code>wordsContainer</code> that share the longest common suffix, find the string that is the <strong>smallest</strong> in length. If there are two or more such strings that have the <strong>same</strong> smallest length, find the one that occurred <strong>earlier</strong> in <code>wordsContainer</code>.</p>
<p>Return <em>an array of integers </em><code>ans</code><em>, where </em><code>ans[i]</code><em> is the index of the string in </em><code>wordsContainer</code><em> that has the <strong>longest common suffix</strong> with </em><code>wordsQuery[i]</code><em>.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">wordsContainer = [&quot;abcd&quot;,&quot;bcd&quot;,&quot;xbcd&quot;], wordsQuery = [&quot;cd&quot;,&quot;bcd&quot;,&quot;xyz&quot;]</span></p>
<p><strong>Output:</strong> <span class="example-io">[1,1,1]</span></p>
<p><strong>Explanation:</strong></p>
<p>Let&#39;s look at each <code>wordsQuery[i]</code> separately:</p>
<ul>
<li>For <code>wordsQuery[0] = &quot;cd&quot;</code>, strings from <code>wordsContainer</code> that share the longest common suffix <code>&quot;cd&quot;</code> are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.</li>
<li>For <code>wordsQuery[1] = &quot;bcd&quot;</code>, strings from <code>wordsContainer</code> that share the longest common suffix <code>&quot;bcd&quot;</code> are at indices 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.</li>
<li>For <code>wordsQuery[2] = &quot;xyz&quot;</code>, there is no string from <code>wordsContainer</code> that shares a common suffix. Hence the longest common suffix is <code>&quot;&quot;</code>, that is shared with strings at index 0, 1, and 2. Among these, the answer is the string at index 1 because it has the shortest length of 3.</li>
</ul>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">wordsContainer = [&quot;abcdefgh&quot;,&quot;poiuygh&quot;,&quot;ghghgh&quot;], wordsQuery = [&quot;gh&quot;,&quot;acbfgh&quot;,&quot;acbfegh&quot;]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,0,2]</span></p>
<p><strong>Explanation:</strong></p>
<p>Let&#39;s look at each <code>wordsQuery[i]</code> separately:</p>
<ul>
<li>For <code>wordsQuery[0] = &quot;gh&quot;</code>, strings from <code>wordsContainer</code> that share the longest common suffix <code>&quot;gh&quot;</code> are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.</li>
<li>For <code>wordsQuery[1] = &quot;acbfgh&quot;</code>, only the string at index 0 shares the longest common suffix <code>&quot;fgh&quot;</code>. Hence it is the answer, even though the string at index 2 is shorter.</li>
<li>For <code>wordsQuery[2] = &quot;acbfegh&quot;</code>, strings from <code>wordsContainer</code> that share the longest common suffix <code>&quot;gh&quot;</code> are at indices 0, 1, and 2. Among these, the answer is the string at index 2 because it has the shortest length of 6.</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= wordsContainer.length, wordsQuery.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= wordsContainer[i].length &lt;= 5 * 10<sup>3</sup></code></li>
<li><code>1 &lt;= wordsQuery[i].length &lt;= 5 * 10<sup>3</sup></code></li>
<li><code>wordsContainer[i]</code> consists only of lowercase English letters.</li>
<li><code>wordsQuery[i]</code> consists only of lowercase English letters.</li>
<li>Sum of <code>wordsContainer[i].length</code> is at most <code>5 * 10<sup>5</sup></code>.</li>
<li>Sum of <code>wordsQuery[i].length</code> is at most <code>5 * 10<sup>5</sup></code>.</li>
</ul>

@ -0,0 +1,49 @@
<p>The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, <code>nums</code> and <code>freq</code>, of equal length <code>n</code>. Each element in <code>nums</code> represents an ID, and the corresponding element in <code>freq</code> indicates how many times that ID should be added to or removed from the collection at each step.</p>
<ul>
<li><strong>Addition of IDs:</strong> If <code>freq[i]</code> is positive, it means <code>freq[i]</code> IDs with the value <code>nums[i]</code> are added to the collection at step <code>i</code>.</li>
<li><strong>Removal of IDs:</strong> If <code>freq[i]</code> is negative, it means <code>-freq[i]</code> IDs with the value <code>nums[i]</code> are removed from the collection at step <code>i</code>.</li>
</ul>
<p>Return an array <code>ans</code> of length <code>n</code>, where <code>ans[i]</code> represents the <strong>count</strong> of the <em>most frequent ID</em> in the collection after the <code>i<sup>th</sup></code>&nbsp;step. If the collection is empty at any step, <code>ans[i]</code> should be 0 for that step.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [2,3,2,1], freq = [3,2,-3,1]</span></p>
<p><strong>Output:</strong> <span class="example-io">[3,3,2,2]</span></p>
<p><strong>Explanation:</strong></p>
<p>After step 0, we have 3 IDs with the value of 2. So <code>ans[0] = 3</code>.<br />
After step 1, we have 3 IDs with the value of 2 and 2 IDs with the value of 3. So <code>ans[1] = 3</code>.<br />
After step 2, we have 2 IDs with the value of 3. So <code>ans[2] = 2</code>.<br />
After step 3, we have 2 IDs with the value of 3 and 1 ID with the value of 1. So <code>ans[3] = 2</code>.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [5,5,3], freq = [2,-2,1]</span></p>
<p><strong>Output:</strong> <span class="example-io">[2,0,1]</span></p>
<p><strong>Explanation:</strong></p>
<p>After step 0, we have 2 IDs with the value of 5. So <code>ans[0] = 2</code>.<br />
After step 1, there are no IDs. So <code>ans[1] = 0</code>.<br />
After step 2, we have 1 ID with the value of 3. So <code>ans[2] = 1</code>.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length == freq.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= freq[i] &lt;= 10<sup>5</sup></code></li>
<li><code>freq[i] != 0</code></li>
<li>The input is generated<!-- notionvc: a136b55a-f319-4fa6-9247-11be9f3b1db8 --> such that the occurrences of an ID will not be negative in any step.</li>
</ul>

@ -0,0 +1,29 @@
Given a string <code>s</code>, return the <strong>maximum</strong> length of a <span data-keyword="substring">substring</span>&nbsp;such that it contains <em>at most two occurrences</em> of each character.
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;bcbbbcba&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">4</span></p>
<p><strong>Explanation:</strong></p>
The following substring has a length of 4 and contains at most two occurrences of each character: <code>&quot;bcbb<u>bcba</u>&quot;</code>.</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">s = &quot;aaaa&quot;</span></p>
<p><strong>Output:</strong> <span class="example-io">2</span></p>
<p><strong>Explanation:</strong></p>
The following substring has a length of 2 and contains at most two occurrences of each character: <code>&quot;<u>aa</u>aa&quot;</code>.</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> consists only of lowercase English letters.</li>
</ul>