mirror of https://github.com/doocs/leetcode.git
feat: update lc problems (#3438)
This commit is contained in:
parent
547f88c0e2
commit
b098694318
|
|
@ -31,13 +31,13 @@ tags:
|
|||
|
||||
<p>对链表进行插入排序。</p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/Insertion-sort-example-300px.gif" /></p>
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130387-qxfMwx-Insertion-sort-example-300px.gif" /></p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/sort1linked-list.jpg" /></p>
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130414-QbPAjl-image.png" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> head = [4,2,1,3]
|
||||
|
|
@ -45,7 +45,7 @@ tags:
|
|||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/sort2linked-list.jpg" /></p>
|
||||
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/0100-0199/0147.Insertion%20Sort%20List/images/1724130432-zoOvdI-image.png" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong> head = [-1,5,3,4,0]
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
|
|
@ -19,7 +19,7 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补完和拼写检查。</p>
|
||||
<p><strong><a href="https://baike.baidu.com/item/字典树/9825209?fr=aladdin" target="_blank">Trie</a></strong>(发音类似 "try")或者说 <strong>前缀树</strong> 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。这一数据结构有相当多的应用情景,例如自动补全和拼写检查。</p>
|
||||
|
||||
<p>请你实现 Trie 类:</p>
|
||||
|
||||
|
|
@ -27,10 +27,10 @@ tags:
|
|||
<li><code>Trie()</code> 初始化前缀树对象。</li>
|
||||
<li><code>void insert(String word)</code> 向前缀树中插入字符串 <code>word</code> 。</li>
|
||||
<li><code>boolean search(String word)</code> 如果字符串 <code>word</code> 在前缀树中,返回 <code>true</code>(即,在检索之前已经插入);否则,返回 <code>false</code> 。</li>
|
||||
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串 <code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>
|
||||
<li><code>boolean startsWith(String prefix)</code> 如果之前已经插入的字符串 <code>word</code> 的前缀之一为 <code>prefix</code> ,返回 <code>true</code> ;否则,返回 <code>false</code> 。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
|
||||
|
|
@ -51,12 +51,12 @@ trie.insert("app");
|
|||
trie.search("app"); // 返回 True
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= word.length, prefix.length <= 2000</code></li>
|
||||
<li><code>1 <= word.length, prefix.length <= 2000</code></li>
|
||||
<li><code>word</code> 和 <code>prefix</code> 仅由小写英文字母组成</li>
|
||||
<li><code>insert</code>、<code>search</code> 和 <code>startsWith</code> 调用次数 <strong>总计</strong> 不超过 <code>3 * 10<sup>4</sup></code> 次</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -20,41 +20,37 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>设计一个电话目录管理系统,让它支持以下功能:</p>
|
||||
<p>设计一个电话目录管理系统,一开始有 <code>maxNumbers</code> 个位置能够储存号码。系统应该存储号码,检查某个位置是否为空,并清空给定的位置。</p>
|
||||
|
||||
<ol>
|
||||
<li><code>get</code>: 分配给用户一个未被使用的电话号码,获取失败请返回 -1</li>
|
||||
<li><code>check</code>: 检查指定的电话号码是否被使用</li>
|
||||
<li><code>release</code>: 释放掉一个电话号码,使其能够重新被分配</li>
|
||||
</ol>
|
||||
<p>实现 <code>PhoneDirectory</code> 类:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>PhoneDirectory(int maxNumbers)</code> 电话目录初始有 <code>maxNumbers</code> 个可用位置。</li>
|
||||
<li><code>int get()</code> 提供一个未分配给任何人的号码。如果没有可用号码则返回 <code>-1</code>。</li>
|
||||
<li><code>bool check(int number)</code> 如果位置 <code>number</code> 可用返回 <code>true</code> 否则返回 <code>false</code>。</li>
|
||||
<li><code>void release(int number)</code> 回收或释放位置 <code>number</code>。</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例:</strong></p>
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>// 初始化电话目录,包括 3 个电话号码:0,1 和 2。
|
||||
PhoneDirectory directory = new PhoneDirectory(3);
|
||||
<pre>
|
||||
<strong>输入:</strong>
|
||||
["PhoneDirectory", "get", "get", "check", "get", "check", "release", "check"]
|
||||
[[3], [], [], [2], [], [2], [2], [2]]
|
||||
<strong>输出:</strong>
|
||||
[null, 0, 1, true, 2, false, null, true]
|
||||
|
||||
// 可以返回任意未分配的号码,这里我们假设它返回 0。
|
||||
directory.get();
|
||||
|
||||
// 假设,函数返回 1。
|
||||
directory.get();
|
||||
|
||||
// 号码 2 未分配,所以返回为 true。
|
||||
directory.check(2);
|
||||
|
||||
// 返回 2,分配后,只剩一个号码未被分配。
|
||||
directory.get();
|
||||
|
||||
// 此时,号码 2 已经被分配,所以返回 false。
|
||||
directory.check(2);
|
||||
|
||||
// 释放号码 2,将该号码变回未分配状态。
|
||||
directory.release(2);
|
||||
|
||||
// 号码 2 现在是未分配状态,所以返回 true。
|
||||
directory.check(2);
|
||||
<strong>解释:</strong>
|
||||
PhoneDirectory phoneDirectory = new PhoneDirectory(3);
|
||||
phoneDirectory.get(); // 它可以返回任意可用的数字。这里我们假设它返回 0。
|
||||
phoneDirectory.get(); // 假设它返回 1。
|
||||
phoneDirectory.check(2); // 数字 2 可用,所以返回 true。
|
||||
phoneDirectory.get(); // 返回剩下的唯一一个数字 2。
|
||||
phoneDirectory.check(2); // 数字 2 不再可用,所以返回 false。
|
||||
phoneDirectory.release(2); // 将数字 2 释放回号码池。
|
||||
phoneDirectory.check(2); // 数字 2 重新可用,返回 true。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
@ -62,9 +58,9 @@ directory.check(2);
|
|||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= maxNumbers <= 10^4</code></li>
|
||||
<li><code>1 <= maxNumbers <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= number < maxNumbers</code></li>
|
||||
<li>调用方法的总数处于区间 <code>[0 - 20000]</code> 之内</li>
|
||||
<li><code>get</code>,<code>check</code> 和 <code>release</code> 最多被调用 <code>2 * 10<sup>4</sup></code> 次。</li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ tags:
|
|||
<ul>
|
||||
<li><code>1 <= rectangles.length <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>rectangles[i].length == 4</code></li>
|
||||
<li><code>-10<sup>5</sup> <= x<sub>i</sub>, y<sub>i</sub>, a<sub>i</sub>, b<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= x<sub>i</sub> < a<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= y<sub>i</sub> < b<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ tags:
|
|||
<ul>
|
||||
<li><code>1 <= rectangles.length <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>rectangles[i].length == 4</code></li>
|
||||
<li><code>-10<sup>5</sup> <= x<sub>i</sub>, y<sub>i</sub>, a<sub>i</sub>, b<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= x<sub>i</sub> < a<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>5</sup> <= y<sub>i</sub> < b<sub>i</sub> <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ Since now the four <b>'s are consecutive, we merge them: "<b&g
|
|||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Note:</strong> This question is the same as 758: <a href="https://leetcode.com/problems/bold-words-in-string/" target="_blank">https://leetcode.com/problems/bold-words-in-string/</a></p>
|
||||
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/bold-words-in-string/description/" target="_blank">758. Bold Words in String</a>.</p>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ tags:
|
|||
<li>例如,<code>"ABC"</code> 表示一个三角形图案,其中一个 <code>“C”</code> 块堆叠在一个 <code>'A'</code> 块(左)和一个 <code>'B'</code> 块(右)之上。请注意,这与 <code>"BAC"</code> 不同,<code>"B"</code> 在左下角,<code>"A"</code> 在右下角。</li>
|
||||
</ul>
|
||||
|
||||
<p>你从底部的一排积木 <code>bottom</code> 开始,作为一个单一的字符串,你 <strong>必须</strong> 使用作为金字塔的底部。</p>
|
||||
<p>你从作为单个字符串给出的底部的一排积木 <code>bottom</code> 开始,<strong>必须</strong> 将其作为金字塔的底部。</p>
|
||||
|
||||
<p>在给定 <code>bottom</code> 和 <code>allowed</code> 的情况下,如果你能一直构建到金字塔顶部,使金字塔中的 <strong>每个三角形图案</strong> 都是允许的,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||
<p>在给定 <code>bottom</code> 和 <code>allowed</code> 的情况下,如果你能一直构建到金字塔顶部,使金字塔中的 <strong>每个三角形图案</strong> 都是在 <code>allowed</code> 中的,则返回 <code>true</code> ,否则返回 <code>false</code> 。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ tags:
|
|||
<pre>
|
||||
<strong>输入:</strong>bottom = "BCD", allowed = ["BCC","CDE","CEA","FFF"]
|
||||
<strong>输出:</strong>true
|
||||
<strong>解释:</strong>允许的三角形模式显示在右边。
|
||||
<strong>解释:</strong>允许的三角形图案显示在右边。
|
||||
从最底层(第 3 层)开始,我们可以在第 2 层构建“CE”,然后在第 1 层构建“E”。
|
||||
金字塔中有三种三角形图案,分别是 “BCC”、“CDE” 和 “CEA”。都是允许的。
|
||||
</pre>
|
||||
|
|
@ -51,8 +51,8 @@ tags:
|
|||
<pre>
|
||||
<strong>输入:</strong>bottom = "AAAA", allowed = ["AAB","AAC","BCD","BBE","DEF"]
|
||||
<strong>输出:</strong>false
|
||||
<strong>解释:</strong>允许的三角形模式显示在右边。
|
||||
从最底层(游戏邦注:即第 4 个关卡)开始,创造第 3 个关卡有多种方法,但如果尝试所有可能性,你便会在创造第 1 个关卡前陷入困境。
|
||||
<strong>解释:</strong>允许的三角形图案显示在右边。
|
||||
从最底层(即第 4 层)开始,创造第 3 层有多种方法,但如果尝试所有可能性,你便会在创造第 1 层前陷入困境。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ tags:
|
|||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Note:</strong> This question is the same as 616: <a href="https://leetcode.com/problems/add-bold-tag-in-string/" target="_blank">https://leetcode.com/problems/add-bold-tag-in-string/</a></p>
|
||||
<p><strong>Note:</strong> This question is the same as <a href="https://leetcode.com/problems/add-bold-tag-in-string/description/" target="_blank">616. Add Bold Tag in String</a>.</p>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>给你一个 <code>m * n</code> 的矩阵,矩阵中的数字 <strong>各不相同</strong> 。请你按 <strong>任意</strong> 顺序返回矩阵中的所有幸运数。</p>
|
||||
<p>给你一个 <code>m x n</code> 的矩阵,矩阵中的数字 <strong>各不相同</strong> 。请你按 <strong>任意</strong> 顺序返回矩阵中的所有幸运数。</p>
|
||||
|
||||
<p><strong>幸运数</strong> 是指矩阵中满足同时下列两个条件的元素:</p>
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ tags:
|
|||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>matrix = [[3,7,8],[9,11,13],[15,16,17]]
|
||||
|
|
@ -38,7 +38,7 @@ tags:
|
|||
<strong>解释:</strong>15 是唯一的幸运数,因为它是其所在行中的最小值,也是所在列中的最大值。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
|
||||
|
|
@ -46,12 +46,12 @@ tags:
|
|||
<strong>解释:</strong>12 是唯一的幸运数,因为它是其所在行中的最小值,也是所在列中的最大值。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
<p><strong class="example">示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>matrix = [[7,8],[1,2]]
|
||||
<strong>输出:</strong>[7]
|
||||
<strong>解释:</strong>7是唯一的幸运数字,因为它是行中的最小值,列中的最大值。
|
||||
<strong>解释:</strong>7 是唯一的幸运数字,因为它是行中的最小值,列中的最大值。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
|
@ -62,7 +62,7 @@ tags:
|
|||
<li><code>m == mat.length</code></li>
|
||||
<li><code>n == mat[i].length</code></li>
|
||||
<li><code>1 <= n, m <= 50</code></li>
|
||||
<li><code>1 <= matrix[i][j] <= 10^5</code></li>
|
||||
<li><code>1 <= matrix[i][j] <= 10<sup>5</sup></code></li>
|
||||
<li>矩阵中的所有元素都是不同的</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: 第 250 场周赛 Q3
|
|||
tags:
|
||||
- 数组
|
||||
- 动态规划
|
||||
- 矩阵
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: Weekly Contest 250 Q3
|
|||
tags:
|
||||
- Array
|
||||
- Dynamic Programming
|
||||
- Matrix
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: 第 273 场周赛 Q4
|
|||
tags:
|
||||
- 数组
|
||||
- 哈希表
|
||||
- 双指针
|
||||
- 枚举
|
||||
- 排序
|
||||
---
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ source: Weekly Contest 273 Q4
|
|||
tags:
|
||||
- Array
|
||||
- Hash Table
|
||||
- Two Pointers
|
||||
- Enumeration
|
||||
- Sorting
|
||||
---
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ User 101:
|
|||
- Spent 7 * 15 = 105 on product 3.
|
||||
User 101 spent the most money on product 3.
|
||||
User 102:
|
||||
- Spent (9 + 7) * 10 = 150 on product 1.
|
||||
- Spent (9 + 6) * 10 = 150 on product 1.
|
||||
- Spent 6 * 25 = 150 on product 2.
|
||||
- Spent 10 * 15 = 150 on product 3.
|
||||
User 102 spent the most money on products 1, 2, and 3.
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ comments: true
|
|||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README.md
|
||||
tags:
|
||||
- 栈
|
||||
- 数组
|
||||
- 哈希表
|
||||
- 排序
|
||||
- 单调栈
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ comments: true
|
|||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README_EN.md
|
||||
tags:
|
||||
- Stack
|
||||
- Array
|
||||
- Hash Table
|
||||
- Sorting
|
||||
- Monotonic Stack
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ difficulty: 中等
|
|||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md
|
||||
tags:
|
||||
- 位运算
|
||||
- 递归
|
||||
- 数组
|
||||
- 动态规划
|
||||
- 回溯
|
||||
- 状态压缩
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ difficulty: Medium
|
|||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README_EN.md
|
||||
tags:
|
||||
- Bit Manipulation
|
||||
- Recursion
|
||||
- Array
|
||||
- Dynamic Programming
|
||||
- Backtracking
|
||||
- Bitmask
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ tags:
|
|||
|
||||
<p>给你两个长度相同的正整数数组 <code>nums</code> 和 <code>target</code>。</p>
|
||||
|
||||
<p>在一次操作中,你可以选择 <code>nums</code> 的任何<span data-keyword="subarray">子数组</span>,并将该子数组内的每个元素的值增加或减少 1。</p>
|
||||
<p>在一次操作中,你可以选择 <code>nums</code> 的任何子数组,并将该子数组内的每个元素的值增加或减少 1。</p>
|
||||
|
||||
<p>返回使 <code>nums</code> 数组变为 <code>target</code> 数组所需的 <strong>最少 </strong>操作次数。</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ tags:
|
|||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.lnegth <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ tags:
|
|||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.lnegth <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3253.Co
|
|||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3253. Construct String with Minimum Cost (Easy) 🔒](https://leetcode.cn/problems/construct-string-with-minimum-cost-easy)
|
||||
# [3253. 以最低成本构建字符串(简单) 🔒](https://leetcode.cn/problems/construct-string-with-minimum-cost-easy)
|
||||
|
||||
[English Version](/solution/3200-3299/3253.Construct%20String%20with%20Minimum%20Cost%20%28Easy%29/README_EN.md)
|
||||
|
||||
|
|
@ -14,59 +14,61 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3253.Co
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>You are given a string <code>target</code>, an array of strings <code>words</code>, and an integer array <code>costs</code>, both arrays of the same length.</p>
|
||||
<p>给定字符串 <code>target</code>,一个字符串数组 <code>words</code> 以及一个整数数组 <code>costs</code>,两个数组长度相同。</p>
|
||||
|
||||
<p>Imagine an empty string <code>s</code>.</p>
|
||||
<p>想象一个空字符串 <code>s</code>。</p>
|
||||
|
||||
<p>You can perform the following operation any number of times (including <strong>zero</strong>):</p>
|
||||
<p>您可以执行以下操作任意次数(包括 <strong>零</strong>):</p>
|
||||
|
||||
<ul>
|
||||
<li>Choose an index <code>i</code> in the range <code>[0, words.length - 1]</code>.</li>
|
||||
<li>Append <code>words[i]</code> to <code>s</code>.</li>
|
||||
<li>The cost of operation is <code>costs[i]</code>.</li>
|
||||
<li>从范围 <code>[0, words.length - 1]</code> 中选择一个下标 <code>i</code>。</li>
|
||||
<li>将 <code>words[i]</code> 添加到 <code>s</code>。</li>
|
||||
<li>操作的开销为 <code>costs[i]</code>。</li>
|
||||
</ul>
|
||||
|
||||
<p>Return the <strong>minimum</strong> cost to make <code>s</code> equal to <code>target</code>. If it's not possible, return -1.</p>
|
||||
<p>返回使 <code>s</code> 与 <code>target</code> 相等的 <strong>最小</strong> 开销。如果不可能做到,返回 -1。</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">target = "abcdef", words = ["abdef","abc","d","def","ef"], costs = [100,1,1,10,5]</span></p>
|
||||
<p><strong>输入:</strong><span class="example-io">target = "abcdef", words = ["abdef","abc","d","def","ef"], costs = [100,1,1,10,5]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">7</span></p>
|
||||
<p><span class="example-io"><b>输出:</b>7</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>The minimum cost can be achieved by performing the following operations:</p>
|
||||
<p>通过执行以下操作可以实现最低开销:</p>
|
||||
|
||||
<ul>
|
||||
<li>Select index 1 and append <code>"abc"</code> to <code>s</code> at a cost of 1, resulting in <code>s = "abc"</code>.</li>
|
||||
<li>Select index 2 and append <code>"d"</code> to <code>s</code> at a cost of 1, resulting in <code>s = "abcd"</code>.</li>
|
||||
<li>Select index 4 and append <code>"ef"</code> to <code>s</code> at a cost of 5, resulting in <code>s = "abcdef"</code>.</li>
|
||||
<li>选择下标 1 然后以 1 的开销将 <code>"abc"</code> 添加到 <code>s</code>,得到 <code>s = "abc"</code>。</li>
|
||||
<li>选择下标 2 然后以 1 的开销将 <code>"d"</code> 添加到 <code>s</code>,得到 <code>s = "abcd"</code>。</li>
|
||||
<li>选择下标 4 然后以 5 的开销将 <code>"ef"</code> 添加到 <code>s</code>,得到 <code>s = "abcdef"</code>。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">target = "aaaa", words = ["z","zz","zzz"], costs = [1,10,100]</span></p>
|
||||
<p><span class="example-io"><b>输入:</b>target = "aaaa", words = ["z","zz","zzz"], costs = [1,10,100]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">-1</span></p>
|
||||
<p><span class="example-io"><b>输出:</b>-1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<p>It is impossible to make <code>s</code> equal to <code>target</code>, so we return -1.</p>
|
||||
<p>不可能使 <code>s</code> 与 <code>target</code> 相等,所以我们返回 -1。</p>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= target.length <= 2000</code></li>
|
||||
<li><code>1 <= words.length == costs.length <= 50</code></li>
|
||||
<li><code>1 <= words[i].length <= target.length</code></li>
|
||||
<li><code>target</code> and <code>words[i]</code> consist only of lowercase English letters.</li>
|
||||
<li><code>target</code> 和 <code>words[i]</code> 只包含小写英语字母。</li>
|
||||
<li><code>1 <= costs[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 滑动窗口
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- Sliding Window
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 滑动窗口
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- Sliding Window
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 动态规划
|
||||
- 枚举
|
||||
- 矩阵
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- Dynamic Programming
|
||||
- Enumeration
|
||||
- Matrix
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 动态规划
|
||||
- 枚举
|
||||
- 矩阵
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- Dynamic Programming
|
||||
- Enumeration
|
||||
- Matrix
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: 简单
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README.md
|
||||
tags:
|
||||
- 字符串
|
||||
- 滑动窗口
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: Easy
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README_EN.md
|
||||
tags:
|
||||
- String
|
||||
- Sliding Window
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 动态规划
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- Dynamic Programming
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README.md
|
||||
tags:
|
||||
- 贪心
|
||||
- 数学
|
||||
- 字符串
|
||||
- 动态规划
|
||||
- 数论
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README_EN.md
|
||||
tags:
|
||||
- Greedy
|
||||
- Math
|
||||
- String
|
||||
- Dynamic Programming
|
||||
- Number Theory
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
comments: true
|
||||
difficulty: 困难
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README.md
|
||||
tags:
|
||||
- 数组
|
||||
- 字符串
|
||||
- 二分查找
|
||||
- 前缀和
|
||||
- 滑动窗口
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
comments: true
|
||||
difficulty: Hard
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README_EN.md
|
||||
tags:
|
||||
- Array
|
||||
- String
|
||||
- Binary Search
|
||||
- Prefix Sum
|
||||
- Sliding Window
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
|
|
|||
|
|
@ -0,0 +1,179 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: 中等
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README.md
|
||||
tags:
|
||||
- 数据库
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3262. Find Overlapping Shifts 🔒](https://leetcode.cn/problems/find-overlapping-shifts)
|
||||
|
||||
[English Version](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README_EN.md)
|
||||
|
||||
## 题目描述
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>Table: <code>EmployeeShifts</code></p>
|
||||
|
||||
<pre>
|
||||
+------------------+---------+
|
||||
| Column Name | Type |
|
||||
+------------------+---------+
|
||||
| employee_id | int |
|
||||
| start_time | time |
|
||||
| end_time | time |
|
||||
+------------------+---------+
|
||||
(employee_id, start_time) is the unique key for this table.
|
||||
This table contains information about the shifts worked by employees, including the start and end times on a specific date.
|
||||
</pre>
|
||||
|
||||
<p>Write a solution to count the number of <strong>overlapping shifts</strong> for each employee. Two shifts are considered overlapping if one shift’s <code>end_time</code> is <strong>later than</strong> another shift’s <code>start_time</code>.</p>
|
||||
|
||||
<p><em>Return the result table ordered by</em> <code>employee_id</code> <em>in <strong>ascending</strong> order</em>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong></p>
|
||||
|
||||
<p><code>EmployeeShifts</code> table:</p>
|
||||
|
||||
<pre class="example-io">
|
||||
+-------------+------------+----------+
|
||||
| employee_id | start_time | end_time |
|
||||
+-------------+------------+----------+
|
||||
| 1 | 08:00:00 | 12:00:00 |
|
||||
| 1 | 11:00:00 | 15:00:00 |
|
||||
| 1 | 14:00:00 | 18:00:00 |
|
||||
| 2 | 09:00:00 | 17:00:00 |
|
||||
| 2 | 16:00:00 | 20:00:00 |
|
||||
| 3 | 10:00:00 | 12:00:00 |
|
||||
| 3 | 13:00:00 | 15:00:00 |
|
||||
| 3 | 16:00:00 | 18:00:00 |
|
||||
| 4 | 08:00:00 | 10:00:00 |
|
||||
| 4 | 09:00:00 | 11:00:00 |
|
||||
+-------------+------------+----------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Output:</strong></p>
|
||||
|
||||
<pre class="example-io">
|
||||
+-------------+--------------------+
|
||||
| employee_id | overlapping_shifts |
|
||||
+-------------+--------------------+
|
||||
| 1 | 2 |
|
||||
| 2 | 1 |
|
||||
| 4 | 1 |
|
||||
+-------------+--------------------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Employee 1 has 3 shifts:
|
||||
<ul>
|
||||
<li>08:00:00 to 12:00:00</li>
|
||||
<li>11:00:00 to 15:00:00</li>
|
||||
<li>14:00:00 to 18:00:00</li>
|
||||
</ul>
|
||||
The first shift overlaps with the second, and the second overlaps with the third, resulting in 2 overlapping shifts.</li>
|
||||
<li>Employee 2 has 2 shifts:
|
||||
<ul>
|
||||
<li>09:00:00 to 17:00:00</li>
|
||||
<li>16:00:00 to 20:00:00</li>
|
||||
</ul>
|
||||
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
|
||||
<li>Employee 3 has 3 shifts:
|
||||
<ul>
|
||||
<li>10:00:00 to 12:00:00</li>
|
||||
<li>13:00:00 to 15:00:00</li>
|
||||
<li>16:00:00 to 18:00:00</li>
|
||||
</ul>
|
||||
None of these shifts overlap, so Employee 3 is not included in the output.</li>
|
||||
<li>Employee 4 has 2 shifts:
|
||||
<ul>
|
||||
<li>08:00:00 to 10:00:00</li>
|
||||
<li>09:00:00 to 11:00:00</li>
|
||||
</ul>
|
||||
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
|
||||
</ul>
|
||||
|
||||
<p>The output shows the employee_id and the count of overlapping shifts for each employee who has at least one overlapping shift, ordered by employee_id in ascending order.</p>
|
||||
</div>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## 解法
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### 方法一:自连接 + 分组计数
|
||||
|
||||
我们首先使用自连接,将 `EmployeeShifts` 表连接自身。通过连接条件,确保只比较同一个员工的班次,并且检查班次之间是否存在重叠。
|
||||
|
||||
1. `t1.start_time < t2.end_time`:确保第一个班次的开始时间早于第二个班次的结束时间。
|
||||
1. `t1.end_time > t2.start_time`:确保第一个班次的结束时间晚于第二个班次的开始时间。
|
||||
1. `t1.start_time != t2.start_time`:避免班次与自身比较。
|
||||
|
||||
接下来,我们对数据按照 `employee_id` 进行分组,统计每个员工的重叠班次数量。这里我们将重叠班次数量除以 2,因为我们在自连接时,每个重叠的班次都会被计算两次。
|
||||
|
||||
最后,我们筛选出重叠班次数量大于 0 的员工,并按照 `employee_id` 进行升序排序。
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### MySQL
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
t1.employee_id,
|
||||
COUNT(*) / 2 AS overlapping_shifts
|
||||
FROM
|
||||
EmployeeShifts t1
|
||||
JOIN EmployeeShifts t2
|
||||
ON t1.employee_id = t2.employee_id
|
||||
AND t1.start_time < t2.end_time
|
||||
AND t1.end_time > t2.start_time
|
||||
AND t1.start_time != t2.start_time
|
||||
GROUP BY 1
|
||||
HAVING overlapping_shifts > 0
|
||||
ORDER BY 1;
|
||||
```
|
||||
|
||||
#### Pandas
|
||||
|
||||
```python
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def find_overlapping_shifts(employee_shifts: pd.DataFrame) -> pd.DataFrame:
|
||||
merged = employee_shifts.merge(
|
||||
employee_shifts, on="employee_id", suffixes=("_1", "_2")
|
||||
)
|
||||
overlap = merged[
|
||||
(merged["start_time_1"] < merged["end_time_2"])
|
||||
& (merged["end_time_1"] > merged["start_time_2"])
|
||||
& (merged["start_time_1"] != merged["start_time_2"])
|
||||
]
|
||||
overlap_counts = (
|
||||
overlap.groupby("employee_id").size().reset_index(name="overlapping_shifts")
|
||||
)
|
||||
overlap_counts["overlapping_shifts"] = overlap_counts["overlapping_shifts"] // 2
|
||||
result = (
|
||||
overlap_counts[overlap_counts["overlapping_shifts"] > 0]
|
||||
.sort_values("employee_id")
|
||||
.reset_index(drop=True)
|
||||
)
|
||||
return result
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
---
|
||||
comments: true
|
||||
difficulty: Medium
|
||||
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README_EN.md
|
||||
tags:
|
||||
- Database
|
||||
---
|
||||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3262. Find Overlapping Shifts 🔒](https://leetcode.com/problems/find-overlapping-shifts)
|
||||
|
||||
[中文文档](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README.md)
|
||||
|
||||
## Description
|
||||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>Table: <code>EmployeeShifts</code></p>
|
||||
|
||||
<pre>
|
||||
+------------------+---------+
|
||||
| Column Name | Type |
|
||||
+------------------+---------+
|
||||
| employee_id | int |
|
||||
| start_time | time |
|
||||
| end_time | time |
|
||||
+------------------+---------+
|
||||
(employee_id, start_time) is the unique key for this table.
|
||||
This table contains information about the shifts worked by employees, including the start and end times on a specific date.
|
||||
</pre>
|
||||
|
||||
<p>Write a solution to count the number of <strong>overlapping shifts</strong> for each employee. Two shifts are considered overlapping if one shift’s <code>end_time</code> is <strong>later than</strong> another shift’s <code>start_time</code>.</p>
|
||||
|
||||
<p><em>Return the result table ordered by</em> <code>employee_id</code> <em>in <strong>ascending</strong> order</em>.</p>
|
||||
|
||||
<p>The query result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong></p>
|
||||
|
||||
<p><code>EmployeeShifts</code> table:</p>
|
||||
|
||||
<pre class="example-io">
|
||||
+-------------+------------+----------+
|
||||
| employee_id | start_time | end_time |
|
||||
+-------------+------------+----------+
|
||||
| 1 | 08:00:00 | 12:00:00 |
|
||||
| 1 | 11:00:00 | 15:00:00 |
|
||||
| 1 | 14:00:00 | 18:00:00 |
|
||||
| 2 | 09:00:00 | 17:00:00 |
|
||||
| 2 | 16:00:00 | 20:00:00 |
|
||||
| 3 | 10:00:00 | 12:00:00 |
|
||||
| 3 | 13:00:00 | 15:00:00 |
|
||||
| 3 | 16:00:00 | 18:00:00 |
|
||||
| 4 | 08:00:00 | 10:00:00 |
|
||||
| 4 | 09:00:00 | 11:00:00 |
|
||||
+-------------+------------+----------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Output:</strong></p>
|
||||
|
||||
<pre class="example-io">
|
||||
+-------------+--------------------+
|
||||
| employee_id | overlapping_shifts |
|
||||
+-------------+--------------------+
|
||||
| 1 | 2 |
|
||||
| 2 | 1 |
|
||||
| 4 | 1 |
|
||||
+-------------+--------------------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Employee 1 has 3 shifts:
|
||||
<ul>
|
||||
<li>08:00:00 to 12:00:00</li>
|
||||
<li>11:00:00 to 15:00:00</li>
|
||||
<li>14:00:00 to 18:00:00</li>
|
||||
</ul>
|
||||
The first shift overlaps with the second, and the second overlaps with the third, resulting in 2 overlapping shifts.</li>
|
||||
<li>Employee 2 has 2 shifts:
|
||||
<ul>
|
||||
<li>09:00:00 to 17:00:00</li>
|
||||
<li>16:00:00 to 20:00:00</li>
|
||||
</ul>
|
||||
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
|
||||
<li>Employee 3 has 3 shifts:
|
||||
<ul>
|
||||
<li>10:00:00 to 12:00:00</li>
|
||||
<li>13:00:00 to 15:00:00</li>
|
||||
<li>16:00:00 to 18:00:00</li>
|
||||
</ul>
|
||||
None of these shifts overlap, so Employee 3 is not included in the output.</li>
|
||||
<li>Employee 4 has 2 shifts:
|
||||
<ul>
|
||||
<li>08:00:00 to 10:00:00</li>
|
||||
<li>09:00:00 to 11:00:00</li>
|
||||
</ul>
|
||||
These shifts overlap with each other, resulting in 1 overlapping shift.</li>
|
||||
</ul>
|
||||
|
||||
<p>The output shows the employee_id and the count of overlapping shifts for each employee who has at least one overlapping shift, ordered by employee_id in ascending order.</p>
|
||||
</div>
|
||||
|
||||
<!-- description:end -->
|
||||
|
||||
## Solutions
|
||||
|
||||
<!-- solution:start -->
|
||||
|
||||
### Solution 1: Self-Join + Group Count
|
||||
|
||||
We start by using a self-join to join the `EmployeeShifts` table with itself. The join condition ensures that only shifts of the same employee are compared, and checks if there is any overlap between the shifts.
|
||||
|
||||
1. `t1.start_time < t2.end_time`: Ensures that the start time of the first shift is earlier than the end time of the second shift.
|
||||
2. `t1.end_time > t2.start_time`: Ensures that the end time of the first shift is later than the start time of the second shift.
|
||||
3. `t1.start_time != t2.start_time`: Avoids comparing a shift with itself.
|
||||
|
||||
Next, we group the data by `employee_id` and count the number of overlapping shifts for each employee. We divide the count by 2 because each overlap is counted twice in the self-join.
|
||||
|
||||
Finally, we filter out employees with an overlapping shift count greater than 0 and sort the results in ascending order by `employee_id`.
|
||||
|
||||
<!-- tabs:start -->
|
||||
|
||||
#### MySQL
|
||||
|
||||
```sql
|
||||
SELECT
|
||||
t1.employee_id,
|
||||
COUNT(*) / 2 AS overlapping_shifts
|
||||
FROM
|
||||
EmployeeShifts t1
|
||||
JOIN EmployeeShifts t2
|
||||
ON t1.employee_id = t2.employee_id
|
||||
AND t1.start_time < t2.end_time
|
||||
AND t1.end_time > t2.start_time
|
||||
AND t1.start_time != t2.start_time
|
||||
GROUP BY 1
|
||||
HAVING overlapping_shifts > 0
|
||||
ORDER BY 1;
|
||||
```
|
||||
|
||||
#### Pandas
|
||||
|
||||
```python
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def find_overlapping_shifts(employee_shifts: pd.DataFrame) -> pd.DataFrame:
|
||||
merged = employee_shifts.merge(
|
||||
employee_shifts, on="employee_id", suffixes=("_1", "_2")
|
||||
)
|
||||
overlap = merged[
|
||||
(merged["start_time_1"] < merged["end_time_2"])
|
||||
& (merged["end_time_1"] > merged["start_time_2"])
|
||||
& (merged["start_time_1"] != merged["start_time_2"])
|
||||
]
|
||||
overlap_counts = (
|
||||
overlap.groupby("employee_id").size().reset_index(name="overlapping_shifts")
|
||||
)
|
||||
overlap_counts["overlapping_shifts"] = overlap_counts["overlapping_shifts"] // 2
|
||||
result = (
|
||||
overlap_counts[overlap_counts["overlapping_shifts"] > 0]
|
||||
.sort_values("employee_id")
|
||||
.reset_index(drop=True)
|
||||
)
|
||||
return result
|
||||
```
|
||||
|
||||
<!-- tabs:end -->
|
||||
|
||||
<!-- solution:end -->
|
||||
|
||||
<!-- problem:end -->
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import pandas as pd
|
||||
|
||||
|
||||
def find_overlapping_shifts(employee_shifts: pd.DataFrame) -> pd.DataFrame:
|
||||
merged = employee_shifts.merge(
|
||||
employee_shifts, on="employee_id", suffixes=("_1", "_2")
|
||||
)
|
||||
overlap = merged[
|
||||
(merged["start_time_1"] < merged["end_time_2"])
|
||||
& (merged["end_time_1"] > merged["start_time_2"])
|
||||
& (merged["start_time_1"] != merged["start_time_2"])
|
||||
]
|
||||
overlap_counts = (
|
||||
overlap.groupby("employee_id").size().reset_index(name="overlapping_shifts")
|
||||
)
|
||||
overlap_counts["overlapping_shifts"] = overlap_counts["overlapping_shifts"] // 2
|
||||
result = (
|
||||
overlap_counts[overlap_counts["overlapping_shifts"] > 0]
|
||||
.sort_values("employee_id")
|
||||
.reset_index(drop=True)
|
||||
)
|
||||
return result
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
SELECT
|
||||
t1.employee_id,
|
||||
COUNT(*) / 2 AS overlapping_shifts
|
||||
FROM
|
||||
EmployeeShifts t1
|
||||
JOIN EmployeeShifts t2
|
||||
ON t1.employee_id = t2.employee_id
|
||||
AND t1.start_time < t2.end_time
|
||||
AND t1.end_time > t2.start_time
|
||||
AND t1.start_time != t2.start_time
|
||||
GROUP BY 1
|
||||
HAVING overlapping_shifts > 0
|
||||
ORDER BY 1;
|
||||
|
|
@ -2730,7 +2730,6 @@ comments: true
|
|||
|
||||
#### 第 154 场周赛(2019-09-15 10:30, 90 分钟) 参赛人数 1299
|
||||
|
||||
- [1189. “气球” 的最大数量](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md)
|
||||
- [1190. 反转每对括号间的子串](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md)
|
||||
- [1191. K 次串联后最大子数组之和](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md)
|
||||
- [1192. 查找集群内的关键连接](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md)
|
||||
|
|
|
|||
|
|
@ -2733,7 +2733,6 @@ If you want to estimate your score changes after the contest ends, you can visit
|
|||
|
||||
#### Weekly Contest 154
|
||||
|
||||
- [1189. Maximum Number of Balloons](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md)
|
||||
- [1190. Reverse Substrings Between Each Pair of Parentheses](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md)
|
||||
- [1191. K-Concatenation Maximum Sum](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md)
|
||||
- [1192. Critical Connections in a Network](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md)
|
||||
|
|
|
|||
|
|
@ -292,6 +292,7 @@
|
|||
| 3236 | [首席执行官下属层级](/solution/3200-3299/3236.CEO%20Subordinate%20Hierarchy/README.md) | `数据库` | 困难 | 🔒 |
|
||||
| 3246 | [英超积分榜排名](/solution/3200-3299/3246.Premier%20League%20Table%20Ranking/README.md) | `数据库` | 简单 | 🔒 |
|
||||
| 3252 | [英超积分榜排名 II](/solution/3200-3299/3252.Premier%20League%20Table%20Ranking%20II/README.md) | `数据库` | 中等 | 🔒 |
|
||||
| 3262 | [Find Overlapping Shifts](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README.md) | | 中等 | 🔒 |
|
||||
|
||||
## 版权
|
||||
|
||||
|
|
|
|||
|
|
@ -290,6 +290,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 3236 | [CEO Subordinate Hierarchy](/solution/3200-3299/3236.CEO%20Subordinate%20Hierarchy/README_EN.md) | `Database` | Hard | 🔒 |
|
||||
| 3246 | [Premier League Table Ranking](/solution/3200-3299/3246.Premier%20League%20Table%20Ranking/README_EN.md) | `Database` | Easy | 🔒 |
|
||||
| 3252 | [Premier League Table Ranking II](/solution/3200-3299/3252.Premier%20League%20Table%20Ranking%20II/README_EN.md) | `Database` | Medium | 🔒 |
|
||||
| 3262 | [Find Overlapping Shifts](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README_EN.md) | | Medium | 🔒 |
|
||||
|
||||
## Copyright
|
||||
|
||||
|
|
|
|||
|
|
@ -1199,7 +1199,6 @@
|
|||
| 1186 | [删除一次得到子数组最大和](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README.md) | `数组`,`动态规划` | 中等 | 第 153 场周赛 |
|
||||
| 1187 | [使数组严格递增](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README.md) | `数组`,`二分查找`,`动态规划`,`排序` | 困难 | 第 153 场周赛 |
|
||||
| 1188 | [设计有限阻塞队列](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README.md) | `多线程` | 中等 | 🔒 |
|
||||
| 1189 | [“气球” 的最大数量](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README.md) | `哈希表`,`字符串`,`计数` | 简单 | 第 154 场周赛 |
|
||||
| 1190 | [反转每对括号间的子串](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README.md) | `栈`,`字符串` | 中等 | 第 154 场周赛 |
|
||||
| 1191 | [K 次串联后最大子数组之和](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README.md) | `数组`,`动态规划` | 中等 | 第 154 场周赛 |
|
||||
| 1192 | [查找集群内的关键连接](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README.md) | `深度优先搜索`,`图`,`双连通分量` | 困难 | 第 154 场周赛 |
|
||||
|
|
@ -1947,7 +1946,7 @@
|
|||
| 1934 | [确认率](/solution/1900-1999/1934.Confirmation%20Rate/README.md) | `数据库` | 中等 | |
|
||||
| 1935 | [可以输入的最大单词数](/solution/1900-1999/1935.Maximum%20Number%20of%20Words%20You%20Can%20Type/README.md) | `哈希表`,`字符串` | 简单 | 第 250 场周赛 |
|
||||
| 1936 | [新增的最少台阶数](/solution/1900-1999/1936.Add%20Minimum%20Number%20of%20Rungs/README.md) | `贪心`,`数组` | 中等 | 第 250 场周赛 |
|
||||
| 1937 | [扣分后的最大得分](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README.md) | `数组`,`动态规划` | 中等 | 第 250 场周赛 |
|
||||
| 1937 | [扣分后的最大得分](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README.md) | `数组`,`动态规划`,`矩阵` | 中等 | 第 250 场周赛 |
|
||||
| 1938 | [查询最大基因差](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README.md) | `位运算`,`深度优先搜索`,`字典树`,`数组`,`哈希表` | 困难 | 第 250 场周赛 |
|
||||
| 1939 | [主动请求确认消息的用户](/solution/1900-1999/1939.Users%20That%20Actively%20Request%20Confirmation%20Messages/README.md) | `数据库` | 简单 | 🔒 |
|
||||
| 1940 | [排序数组之间的最长公共子序列](/solution/1900-1999/1940.Longest%20Common%20Subsequence%20Between%20Sorted%20Arrays/README.md) | `数组`,`哈希表`,`计数` | 中等 | 🔒 |
|
||||
|
|
@ -2132,7 +2131,7 @@
|
|||
| 2119 | [反转两次的数字](/solution/2100-2199/2119.A%20Number%20After%20a%20Double%20Reversal/README.md) | `数学` | 简单 | 第 273 场周赛 |
|
||||
| 2120 | [执行所有后缀指令](/solution/2100-2199/2120.Execution%20of%20All%20Suffix%20Instructions%20Staying%20in%20a%20Grid/README.md) | `字符串`,`模拟` | 中等 | 第 273 场周赛 |
|
||||
| 2121 | [相同元素的间隔之和](/solution/2100-2199/2121.Intervals%20Between%20Identical%20Elements/README.md) | `数组`,`哈希表`,`前缀和` | 中等 | 第 273 场周赛 |
|
||||
| 2122 | [还原原数组](/solution/2100-2199/2122.Recover%20the%20Original%20Array/README.md) | `数组`,`哈希表`,`枚举`,`排序` | 困难 | 第 273 场周赛 |
|
||||
| 2122 | [还原原数组](/solution/2100-2199/2122.Recover%20the%20Original%20Array/README.md) | `数组`,`哈希表`,`双指针`,`枚举`,`排序` | 困难 | 第 273 场周赛 |
|
||||
| 2123 | [使矩阵中的 1 互不相邻的最小操作数](/solution/2100-2199/2123.Minimum%20Operations%20to%20Remove%20Adjacent%20Ones%20in%20Matrix/README.md) | `图`,`数组`,`矩阵` | 困难 | 🔒 |
|
||||
| 2124 | [检查是否所有 A 都在 B 之前](/solution/2100-2199/2124.Check%20if%20All%20A%27s%20Appears%20Before%20All%20B%27s/README.md) | `字符串` | 简单 | 第 274 场周赛 |
|
||||
| 2125 | [银行中的激光束数量](/solution/2100-2199/2125.Number%20of%20Laser%20Beams%20in%20a%20Bank/README.md) | `数组`,`数学`,`字符串`,`矩阵` | 中等 | 第 274 场周赛 |
|
||||
|
|
@ -2873,7 +2872,7 @@
|
|||
| 2860 | [让所有学生保持开心的分组方法数](/solution/2800-2899/2860.Happy%20Students/README.md) | `数组`,`枚举`,`排序` | 中等 | 第 363 场周赛 |
|
||||
| 2861 | [最大合金数](/solution/2800-2899/2861.Maximum%20Number%20of%20Alloys/README.md) | `数组`,`二分查找` | 中等 | 第 363 场周赛 |
|
||||
| 2862 | [完全子集的最大元素和](/solution/2800-2899/2862.Maximum%20Element-Sum%20of%20a%20Complete%20Subset%20of%20Indices/README.md) | `数组`,`数学`,`数论` | 困难 | 第 363 场周赛 |
|
||||
| 2863 | [最长半递减数组](/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README.md) | `数组`,`哈希表`,`排序` | 中等 | 🔒 |
|
||||
| 2863 | [最长半递减数组](/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README.md) | `栈`,`数组`,`排序`,`单调栈` | 中等 | 🔒 |
|
||||
| 2864 | [最大二进制奇数](/solution/2800-2899/2864.Maximum%20Odd%20Binary%20Number/README.md) | `贪心`,`数学`,`字符串` | 简单 | 第 364 场周赛 |
|
||||
| 2865 | [美丽塔 I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 |
|
||||
| 2866 | [美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 |
|
||||
|
|
@ -3002,7 +3001,7 @@
|
|||
| 2989 | [班级表现](/solution/2900-2999/2989.Class%20Performance/README.md) | `数据库` | 中等 | 🔒 |
|
||||
| 2990 | [贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) | `数据库` | 简单 | 🔒 |
|
||||
| 2991 | [最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) | `数据库` | 困难 | 🔒 |
|
||||
| 2992 | [自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md) | `位运算`,`递归`,`数组`,`动态规划`,`状态压缩` | 中等 | 🔒 |
|
||||
| 2992 | [自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md) | `位运算`,`数组`,`动态规划`,`回溯`,`状态压缩` | 中等 | 🔒 |
|
||||
| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
|
||||
| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
|
||||
| 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 |
|
||||
|
|
@ -3263,15 +3262,16 @@
|
|||
| 3250 | [单调数组对的数目 I](/solution/3200-3299/3250.Find%20the%20Count%20of%20Monotonic%20Pairs%20I/README.md) | `数组`,`数学`,`动态规划`,`组合数学`,`前缀和` | 困难 | 第 410 场周赛 |
|
||||
| 3251 | [单调数组对的数目 II](/solution/3200-3299/3251.Find%20the%20Count%20of%20Monotonic%20Pairs%20II/README.md) | `数组`,`数学`,`动态规划`,`组合数学`,`前缀和` | 困难 | 第 410 场周赛 |
|
||||
| 3252 | [英超积分榜排名 II](/solution/3200-3299/3252.Premier%20League%20Table%20Ranking%20II/README.md) | `数据库` | 中等 | 🔒 |
|
||||
| 3253 | [Construct String with Minimum Cost (Easy)](/solution/3200-3299/3253.Construct%20String%20with%20Minimum%20Cost%20%28Easy%29/README.md) | | 中等 | 🔒 |
|
||||
| 3254 | [长度为 K 的子数组的能量值 I](/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README.md) | | 中等 | 第 137 场双周赛 |
|
||||
| 3255 | [长度为 K 的子数组的能量值 II](/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README.md) | | 中等 | 第 137 场双周赛 |
|
||||
| 3256 | [放三个车的价值之和最大 I](/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README.md) | | 困难 | 第 137 场双周赛 |
|
||||
| 3257 | [放三个车的价值之和最大 II](/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README.md) | | 困难 | 第 137 场双周赛 |
|
||||
| 3258 | [统计满足 K 约束的子字符串数量 I](/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README.md) | | 简单 | 第 411 场周赛 |
|
||||
| 3259 | [超级饮料的最大强化能量](/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README.md) | | 中等 | 第 411 场周赛 |
|
||||
| 3260 | [找出最大的 N 位 K 回文数](/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README.md) | | 困难 | 第 411 场周赛 |
|
||||
| 3261 | [统计满足 K 约束的子字符串数量 II](/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README.md) | | 困难 | 第 411 场周赛 |
|
||||
| 3253 | [以最低成本构建字符串(简单)](/solution/3200-3299/3253.Construct%20String%20with%20Minimum%20Cost%20%28Easy%29/README.md) | | 中等 | 🔒 |
|
||||
| 3254 | [长度为 K 的子数组的能量值 I](/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README.md) | `数组`,`滑动窗口` | 中等 | 第 137 场双周赛 |
|
||||
| 3255 | [长度为 K 的子数组的能量值 II](/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README.md) | `数组`,`滑动窗口` | 中等 | 第 137 场双周赛 |
|
||||
| 3256 | [放三个车的价值之和最大 I](/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README.md) | `数组`,`动态规划`,`枚举`,`矩阵` | 困难 | 第 137 场双周赛 |
|
||||
| 3257 | [放三个车的价值之和最大 II](/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README.md) | `数组`,`动态规划`,`枚举`,`矩阵` | 困难 | 第 137 场双周赛 |
|
||||
| 3258 | [统计满足 K 约束的子字符串数量 I](/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README.md) | `字符串`,`滑动窗口` | 简单 | 第 411 场周赛 |
|
||||
| 3259 | [超级饮料的最大强化能量](/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README.md) | `数组`,`动态规划` | 中等 | 第 411 场周赛 |
|
||||
| 3260 | [找出最大的 N 位 K 回文数](/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README.md) | `贪心`,`数学`,`字符串`,`动态规划`,`数论` | 困难 | 第 411 场周赛 |
|
||||
| 3261 | [统计满足 K 约束的子字符串数量 II](/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README.md) | `数组`,`字符串`,`二分查找`,`前缀和`,`滑动窗口` | 困难 | 第 411 场周赛 |
|
||||
| 3262 | [Find Overlapping Shifts](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README.md) | | 中等 | 🔒 |
|
||||
|
||||
## 版权
|
||||
|
||||
|
|
|
|||
|
|
@ -1197,7 +1197,6 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 1186 | [Maximum Subarray Sum with One Deletion](/solution/1100-1199/1186.Maximum%20Subarray%20Sum%20with%20One%20Deletion/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 153 |
|
||||
| 1187 | [Make Array Strictly Increasing](/solution/1100-1199/1187.Make%20Array%20Strictly%20Increasing/README_EN.md) | `Array`,`Binary Search`,`Dynamic Programming`,`Sorting` | Hard | Weekly Contest 153 |
|
||||
| 1188 | [Design Bounded Blocking Queue](/solution/1100-1199/1188.Design%20Bounded%20Blocking%20Queue/README_EN.md) | `Concurrency` | Medium | 🔒 |
|
||||
| 1189 | [Maximum Number of Balloons](/solution/1100-1199/1189.Maximum%20Number%20of%20Balloons/README_EN.md) | `Hash Table`,`String`,`Counting` | Easy | Weekly Contest 154 |
|
||||
| 1190 | [Reverse Substrings Between Each Pair of Parentheses](/solution/1100-1199/1190.Reverse%20Substrings%20Between%20Each%20Pair%20of%20Parentheses/README_EN.md) | `Stack`,`String` | Medium | Weekly Contest 154 |
|
||||
| 1191 | [K-Concatenation Maximum Sum](/solution/1100-1199/1191.K-Concatenation%20Maximum%20Sum/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 154 |
|
||||
| 1192 | [Critical Connections in a Network](/solution/1100-1199/1192.Critical%20Connections%20in%20a%20Network/README_EN.md) | `Depth-First Search`,`Graph`,`Biconnected Component` | Hard | Weekly Contest 154 |
|
||||
|
|
@ -1945,7 +1944,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 1934 | [Confirmation Rate](/solution/1900-1999/1934.Confirmation%20Rate/README_EN.md) | `Database` | Medium | |
|
||||
| 1935 | [Maximum Number of Words You Can Type](/solution/1900-1999/1935.Maximum%20Number%20of%20Words%20You%20Can%20Type/README_EN.md) | `Hash Table`,`String` | Easy | Weekly Contest 250 |
|
||||
| 1936 | [Add Minimum Number of Rungs](/solution/1900-1999/1936.Add%20Minimum%20Number%20of%20Rungs/README_EN.md) | `Greedy`,`Array` | Medium | Weekly Contest 250 |
|
||||
| 1937 | [Maximum Number of Points with Cost](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 250 |
|
||||
| 1937 | [Maximum Number of Points with Cost](/solution/1900-1999/1937.Maximum%20Number%20of%20Points%20with%20Cost/README_EN.md) | `Array`,`Dynamic Programming`,`Matrix` | Medium | Weekly Contest 250 |
|
||||
| 1938 | [Maximum Genetic Difference Query](/solution/1900-1999/1938.Maximum%20Genetic%20Difference%20Query/README_EN.md) | `Bit Manipulation`,`Depth-First Search`,`Trie`,`Array`,`Hash Table` | Hard | Weekly Contest 250 |
|
||||
| 1939 | [Users That Actively Request Confirmation Messages](/solution/1900-1999/1939.Users%20That%20Actively%20Request%20Confirmation%20Messages/README_EN.md) | `Database` | Easy | 🔒 |
|
||||
| 1940 | [Longest Common Subsequence Between Sorted Arrays](/solution/1900-1999/1940.Longest%20Common%20Subsequence%20Between%20Sorted%20Arrays/README_EN.md) | `Array`,`Hash Table`,`Counting` | Medium | 🔒 |
|
||||
|
|
@ -2130,7 +2129,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 2119 | [A Number After a Double Reversal](/solution/2100-2199/2119.A%20Number%20After%20a%20Double%20Reversal/README_EN.md) | `Math` | Easy | Weekly Contest 273 |
|
||||
| 2120 | [Execution of All Suffix Instructions Staying in a Grid](/solution/2100-2199/2120.Execution%20of%20All%20Suffix%20Instructions%20Staying%20in%20a%20Grid/README_EN.md) | `String`,`Simulation` | Medium | Weekly Contest 273 |
|
||||
| 2121 | [Intervals Between Identical Elements](/solution/2100-2199/2121.Intervals%20Between%20Identical%20Elements/README_EN.md) | `Array`,`Hash Table`,`Prefix Sum` | Medium | Weekly Contest 273 |
|
||||
| 2122 | [Recover the Original Array](/solution/2100-2199/2122.Recover%20the%20Original%20Array/README_EN.md) | `Array`,`Hash Table`,`Enumeration`,`Sorting` | Hard | Weekly Contest 273 |
|
||||
| 2122 | [Recover the Original Array](/solution/2100-2199/2122.Recover%20the%20Original%20Array/README_EN.md) | `Array`,`Hash Table`,`Two Pointers`,`Enumeration`,`Sorting` | Hard | Weekly Contest 273 |
|
||||
| 2123 | [Minimum Operations to Remove Adjacent Ones in Matrix](/solution/2100-2199/2123.Minimum%20Operations%20to%20Remove%20Adjacent%20Ones%20in%20Matrix/README_EN.md) | `Graph`,`Array`,`Matrix` | Hard | 🔒 |
|
||||
| 2124 | [Check if All A's Appears Before All B's](/solution/2100-2199/2124.Check%20if%20All%20A%27s%20Appears%20Before%20All%20B%27s/README_EN.md) | `String` | Easy | Weekly Contest 274 |
|
||||
| 2125 | [Number of Laser Beams in a Bank](/solution/2100-2199/2125.Number%20of%20Laser%20Beams%20in%20a%20Bank/README_EN.md) | `Array`,`Math`,`String`,`Matrix` | Medium | Weekly Contest 274 |
|
||||
|
|
@ -2871,7 +2870,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 2860 | [Happy Students](/solution/2800-2899/2860.Happy%20Students/README_EN.md) | `Array`,`Enumeration`,`Sorting` | Medium | Weekly Contest 363 |
|
||||
| 2861 | [Maximum Number of Alloys](/solution/2800-2899/2861.Maximum%20Number%20of%20Alloys/README_EN.md) | `Array`,`Binary Search` | Medium | Weekly Contest 363 |
|
||||
| 2862 | [Maximum Element-Sum of a Complete Subset of Indices](/solution/2800-2899/2862.Maximum%20Element-Sum%20of%20a%20Complete%20Subset%20of%20Indices/README_EN.md) | `Array`,`Math`,`Number Theory` | Hard | Weekly Contest 363 |
|
||||
| 2863 | [Maximum Length of Semi-Decreasing Subarrays](/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README_EN.md) | `Array`,`Hash Table`,`Sorting` | Medium | 🔒 |
|
||||
| 2863 | [Maximum Length of Semi-Decreasing Subarrays](/solution/2800-2899/2863.Maximum%20Length%20of%20Semi-Decreasing%20Subarrays/README_EN.md) | `Stack`,`Array`,`Sorting`,`Monotonic Stack` | Medium | 🔒 |
|
||||
| 2864 | [Maximum Odd Binary Number](/solution/2800-2899/2864.Maximum%20Odd%20Binary%20Number/README_EN.md) | `Greedy`,`Math`,`String` | Easy | Weekly Contest 364 |
|
||||
| 2865 | [Beautiful Towers I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 |
|
||||
| 2866 | [Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 |
|
||||
|
|
@ -3000,7 +2999,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 2989 | [Class Performance](/solution/2900-2999/2989.Class%20Performance/README_EN.md) | `Database` | Medium | 🔒 |
|
||||
| 2990 | [Loan Types](/solution/2900-2999/2990.Loan%20Types/README_EN.md) | `Database` | Easy | 🔒 |
|
||||
| 2991 | [Top Three Wineries](/solution/2900-2999/2991.Top%20Three%20Wineries/README_EN.md) | `Database` | Hard | 🔒 |
|
||||
| 2992 | [Number of Self-Divisible Permutations](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README_EN.md) | `Bit Manipulation`,`Recursion`,`Array`,`Dynamic Programming`,`Bitmask` | Medium | 🔒 |
|
||||
| 2992 | [Number of Self-Divisible Permutations](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README_EN.md) | `Bit Manipulation`,`Array`,`Dynamic Programming`,`Backtracking`,`Bitmask` | Medium | 🔒 |
|
||||
| 2993 | [Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README_EN.md) | `Database` | Medium | 🔒 |
|
||||
| 2994 | [Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README_EN.md) | `Database` | Hard | 🔒 |
|
||||
| 2995 | [Viewers Turned Streamers](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README_EN.md) | `Database` | Hard | 🔒 |
|
||||
|
|
@ -3262,14 +3261,15 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 3251 | [Find the Count of Monotonic Pairs II](/solution/3200-3299/3251.Find%20the%20Count%20of%20Monotonic%20Pairs%20II/README_EN.md) | `Array`,`Math`,`Dynamic Programming`,`Combinatorics`,`Prefix Sum` | Hard | Weekly Contest 410 |
|
||||
| 3252 | [Premier League Table Ranking II](/solution/3200-3299/3252.Premier%20League%20Table%20Ranking%20II/README_EN.md) | `Database` | Medium | 🔒 |
|
||||
| 3253 | [Construct String with Minimum Cost (Easy)](/solution/3200-3299/3253.Construct%20String%20with%20Minimum%20Cost%20%28Easy%29/README_EN.md) | | Medium | 🔒 |
|
||||
| 3254 | [Find the Power of K-Size Subarrays I](/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README_EN.md) | | Medium | Biweekly Contest 137 |
|
||||
| 3255 | [Find the Power of K-Size Subarrays II](/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README_EN.md) | | Medium | Biweekly Contest 137 |
|
||||
| 3256 | [Maximum Value Sum by Placing Three Rooks I](/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README_EN.md) | | Hard | Biweekly Contest 137 |
|
||||
| 3257 | [Maximum Value Sum by Placing Three Rooks II](/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README_EN.md) | | Hard | Biweekly Contest 137 |
|
||||
| 3258 | [Count Substrings That Satisfy K-Constraint I](/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README_EN.md) | | Easy | Weekly Contest 411 |
|
||||
| 3259 | [Maximum Energy Boost From Two Drinks](/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README_EN.md) | | Medium | Weekly Contest 411 |
|
||||
| 3260 | [Find the Largest Palindrome Divisible by K](/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README_EN.md) | | Hard | Weekly Contest 411 |
|
||||
| 3261 | [Count Substrings That Satisfy K-Constraint II](/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README_EN.md) | | Hard | Weekly Contest 411 |
|
||||
| 3254 | [Find the Power of K-Size Subarrays I](/solution/3200-3299/3254.Find%20the%20Power%20of%20K-Size%20Subarrays%20I/README_EN.md) | `Array`,`Sliding Window` | Medium | Biweekly Contest 137 |
|
||||
| 3255 | [Find the Power of K-Size Subarrays II](/solution/3200-3299/3255.Find%20the%20Power%20of%20K-Size%20Subarrays%20II/README_EN.md) | `Array`,`Sliding Window` | Medium | Biweekly Contest 137 |
|
||||
| 3256 | [Maximum Value Sum by Placing Three Rooks I](/solution/3200-3299/3256.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20I/README_EN.md) | `Array`,`Dynamic Programming`,`Enumeration`,`Matrix` | Hard | Biweekly Contest 137 |
|
||||
| 3257 | [Maximum Value Sum by Placing Three Rooks II](/solution/3200-3299/3257.Maximum%20Value%20Sum%20by%20Placing%20Three%20Rooks%20II/README_EN.md) | `Array`,`Dynamic Programming`,`Enumeration`,`Matrix` | Hard | Biweekly Contest 137 |
|
||||
| 3258 | [Count Substrings That Satisfy K-Constraint I](/solution/3200-3299/3258.Count%20Substrings%20That%20Satisfy%20K-Constraint%20I/README_EN.md) | `String`,`Sliding Window` | Easy | Weekly Contest 411 |
|
||||
| 3259 | [Maximum Energy Boost From Two Drinks](/solution/3200-3299/3259.Maximum%20Energy%20Boost%20From%20Two%20Drinks/README_EN.md) | `Array`,`Dynamic Programming` | Medium | Weekly Contest 411 |
|
||||
| 3260 | [Find the Largest Palindrome Divisible by K](/solution/3200-3299/3260.Find%20the%20Largest%20Palindrome%20Divisible%20by%20K/README_EN.md) | `Greedy`,`Math`,`String`,`Dynamic Programming`,`Number Theory` | Hard | Weekly Contest 411 |
|
||||
| 3261 | [Count Substrings That Satisfy K-Constraint II](/solution/3200-3299/3261.Count%20Substrings%20That%20Satisfy%20K-Constraint%20II/README_EN.md) | `Array`,`String`,`Binary Search`,`Prefix Sum`,`Sliding Window` | Hard | Weekly Contest 411 |
|
||||
| 3262 | [Find Overlapping Shifts](/solution/3200-3299/3262.Find%20Overlapping%20Shifts/README_EN.md) | | Medium | 🔒 |
|
||||
|
||||
## Copyright
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue