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 2023-11-27 09:10:49 +08:00
parent b011971a71
commit 26fce95b5c
66 changed files with 20698 additions and 14119 deletions
README.md
leetcode-cn
origin-data.json
originData
problem (Chinese)
problem (English)
leetcode
requirements.txt

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

File diff suppressed because it is too large Load Diff

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

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

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,51 @@
<p>给你一个下标从 <strong>0 </strong>开始的 <strong>正整数</strong> 数组 <code>nums</code> 和一个 <strong>正整数</strong> <code>limit</code></p>
<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>
<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>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,5,3,9,8], limit = 2
<strong>输出:</strong>[1,3,5,8,9]
<strong>解释:</strong>执行 2 次操作:
- 交换 nums[1] 和 nums[2] 。数组变为 [1,3,5,9,8] 。
- 交换 nums[3] 和 nums[4] 。数组变为 [1,3,5,8,9] 。
即便执行更多次操作,也无法得到字典序更小的数组。
注意,执行不同的操作也可能会得到相同的结果。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,7,6,18,2,1], limit = 3
<strong>输出:</strong>[1,6,7,18,1,2]
<strong>解释:</strong>执行 3 次操作:
- 交换 nums[1] 和 nums[2] 。数组变为 [1,6,7,18,2,1] 。
- 交换 nums[0] 和 nums[4] 。数组变为 [2,6,7,18,1,1] 。
- 交换 nums[0] 和 nums[5] 。数组变为 [1,6,7,18,1,2] 。
即便执行更多次操作,也无法得到字典序更小的数组。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [1,7,28,19,10], limit = 3
<strong>输出:</strong>[1,7,28,19,10]
<strong>解释:</strong>[1,7,28,19,10] 是字典序最小的数组,因为不管怎么选择下标都无法执行操作。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,31 @@
<p>给你三个字符串 <code>s1</code><code>s2</code><code>s3</code>。 你可以根据需要对这三个字符串执行以下操作 <strong>任意次数</strong> <!-- notionvc: b5178de7-3318-4129-b7d9-726b47e90621 --></p>
<p>在每次操作中,你可以选择其中一个长度至少为 <code>2</code> 的字符串 <!-- notionvc: 3342ac46-33c8-4010-aacd-e58678ce31ef --> 并删除其 <strong>最右位置上</strong> 的字符。</p>
<p>如果存在某种方法能够使这三个字符串相等,请返回使它们相等所需的 <strong>最小</strong> 操作次数;否则,返回 <code>-1</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>s1 = "abc"s2 = "abb"s3 = "ab"
<strong>输出:</strong>2
<strong>解释:</strong>对 s1 和 s2 进行一次操作后,可以得到三个相等的字符串。
可以证明,不可能用少于两次操作使它们相等。</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>s1 = "dac"s2 = "bac"s3 = "cac"
<strong>输出:</strong>-1
<strong>解释:</strong>因为 s1 和 s2 的最左位置上的字母<!-- notionvc: 47239f7c-eec1-49f8-af79-c206ec88cb07 -->不相等,所以无论进行多少次操作,它们都不可能相等。因此答案是 -1 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s1.length, s2.length, s3.length &lt;= 100</code></li>
<li><code>s1</code><code>s2</code><code>s3</code> 仅由小写英文字母组成。</li>
</ul>

@ -0,0 +1,46 @@
<p>桌子上有 <code>n</code> 个球,每个球的颜色不是黑色,就是白色。</p>
<p>给你一个长度为 <code>n</code> 、下标从 <strong>0</strong> 开始的二进制字符串 <code>s</code>,其中 <code>1</code><code>0</code> 分别代表黑色和白色的球。</p>
<p>在每一步中,你可以选择两个相邻的球并交换它们。</p>
<p>返回「将所有黑色球都移到右侧,所有白色球都移到左侧所需的 <strong>最小步数</strong>」。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "101"
<strong>输出:</strong>1
<strong>解释:</strong>我们可以按以下方式将所有黑色球移到右侧:
- 交换 s[0] 和 s[1]s = "011"。
最开始1 没有都在右侧,需要至少 1 步将其移到右侧。</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "100"
<strong>输出:</strong>2
<strong>解释:</strong>我们可以按以下方式将所有黑色球移到右侧:
- 交换 s[0] 和 s[1]s = "010"。
- 交换 s[1] 和 s[2]s = "001"。
可以证明所需的最小步数为 2 。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "0111"
<strong>输出:</strong>0
<strong>解释:</strong>所有黑色球都已经在右侧。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n == s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code> 不是 <code>'0'</code>,就是 <code>'1'</code></li>
</ul>

@ -0,0 +1,46 @@
<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>如果初始矩阵和最终矩阵完全相同,则返回 <code>true</code> ,否则返回 <code>false</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
<strong>输出:</strong>true
<strong>解释:</strong>
<img alt="" src="https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png" style="width: 500px; height: 117px;" />
初始矩阵如图一所示。
图二表示对奇数行右移一次且对偶数行左移一次后的矩阵状态。
图三是经过两次循环移位后的最终矩阵状态,与初始矩阵相同。
因此,返回 true 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>mat = [[2,2],[2,2]], k = 3
<strong>输出:</strong>true
<strong>解释:</strong>由于矩阵中的所有值都相等,即使进行循环移位,矩阵仍然保持不变。因此,返回 true 。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>mat = [[1,2]], k = 1
<strong>输出:</strong>false
<strong>解释:</strong>循环移位一次后mat = [[2,1]],与初始矩阵不相等。因此,返回 false 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= mat.length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>
<li><code>1 &lt;= k &lt;= 50</code></li>
</ul>

@ -0,0 +1,49 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的正整数数组&nbsp;<code>heights</code>&nbsp;,其中&nbsp;<code>heights[i]</code>&nbsp;表示第 <code>i</code>&nbsp;栋建筑的高度。</p>
<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>
<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>
<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>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
<b>输出:</b>[2,5,-1,5,2]
<b>解释:</b>第一个查询中Alice 和 Bob 可以移动到建筑 2 ,因为 heights[0] &lt; heights[2] 且 heights[1] &lt; heights[2] 。
第二个查询中Alice 和 Bob 可以移动到建筑 5 ,因为 heights[0] &lt; heights[5] 且 heights[3] &lt; heights[5] 。
第三个查询中Alice 无法与 Bob 相遇,因为 Alice 不能移动到任何其他建筑。
第四个查询中Alice 和 Bob 可以移动到建筑 5 ,因为 heights[3] &lt; heights[5] 且 heights[4] &lt; heights[5] 。
第五个查询中Alice 和 Bob 已经在同一栋建筑中。
对于 ans[i] != -1 ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。
对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
<b>输出:</b>[7,6,-1,4,6]
<strong>解释:</strong>第一个查询中Alice 可以直接移动到 Bob 的建筑,因为 heights[0] &lt; heights[7] 。
第二个查询中Alice 和 Bob 可以移动到建筑 6 ,因为 heights[3] &lt; heights[6] 且 heights[5] &lt; heights[6] 。
第三个查询中Alice 无法与 Bob 相遇,因为 Bob 不能移动到任何其他建筑。
第四个查询中Alice 和 Bob 可以移动到建筑 4 ,因为 heights[3] &lt; heights[4] 且 heights[0] &lt; heights[4] 。
第五个查询中Alice 可以直接移动到 Bob 的建筑,因为 heights[1] &lt; heights[6] 。
对于 ans[i] != -1 ans[i] 是 Alice 和 Bob 可以相遇的建筑中最左边建筑的下标。
对于 ans[i] == -1 ,不存在 Alice 和 Bob 可以相遇的建筑。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= heights.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= heights[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= heights.length - 1</code></li>
</ul>

@ -0,0 +1,48 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums</code>&nbsp;</p>
<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>
<p>请你返回执行任意次操作以后,可以得到的 <strong>最长非递减</strong>&nbsp;数组的长度。</p>
<p><strong>子数组</strong>&nbsp;指的是一个数组中一段连续 <strong>非空</strong>&nbsp;的元素序列。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [5,2,2]
<b>输出:</b>1
<strong>解释:</strong>这个长度为 3 的数组不是非递减的。
我们有 2 种方案使数组长度为 2 。
第一种,选择子数组 [2,2] ,对数组执行操作后得到 [5,4] 。
第二种,选择子数组 [5,2] ,对数组执行操作后得到 [7,2] 。
这两种方案中,数组最后都不是 <strong>非递减</strong>&nbsp;的,所以不是可行的答案。
如果我们选择子数组 [5,2,2] ,并将它替换为 [9] ,数组变成非递减的。
所以答案为 1 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [1,2,3,4]
<b>输出:</b>4
<b>解释:</b>数组已经是非递减的。所以答案为 4 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [4,3,2,6]
<b>输出:</b>3
<b>解释:</b>将 [3,2] 替换为 [5] ,得到数组 [4,5,6] ,它是非递减的。
最大可能的答案为 3 。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,89 @@
<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>
<p>所有线段的编号从 <strong>1</strong>&nbsp;开始。</p>
<p>给你两个整数&nbsp;<code>n</code>&nbsp;<code>m</code>&nbsp;</p>
<p>同时给你两个整数数组&nbsp;<code>hBars</code>&nbsp;<code>vBars</code>&nbsp;</p>
<ul>
<li><code>hBars</code> 包含区间&nbsp;<code>[2, n + 1]</code>&nbsp;&nbsp;<strong>互不相同</strong>&nbsp;的横线段编号。</li>
<li><code>vBars</code>&nbsp;包含&nbsp;<code>[2, m + 1]</code>&nbsp;&nbsp;<strong>互不相同的</strong>&nbsp;竖线段编号。</li>
</ul>
<p>如果满足以下条件之一,你可以 <strong>移除</strong>&nbsp;两个数组中的部分线段:</p>
<ul>
<li>如果移除的是横线段,它必须是&nbsp;<code>hBars</code>&nbsp;中的值。</li>
<li>如果移除的是竖线段,它必须是&nbsp;<code>vBars</code>&nbsp;中的值。</li>
</ul>
<p>请你返回移除一些线段后(<strong>可能不移除任何线段)</strong>,剩余网格图中 <strong>最大正方形</strong>&nbsp;空洞的面积,正方形空洞的意思是正方形 <strong>内部</strong> 不含有任何线段。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<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>
<pre>
<b>输入:</b>n = 2, m = 1, hBars = [2,3], vBars = [2]
<b>输出:</b>4
<b>解释:</b>左边的图是一开始的网格图。
横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,3] 。
可以移除的横线段为 [2,3] ,竖线段为 [2] 。
一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。
操作后得到的网格图如右图所示。
正方形空洞面积为 4。
无法得到面积大于 4 的正方形空洞。
所以答案为 4 。
</pre>
<p><strong class="example">示例 2</strong></p>
<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>
<pre>
<b>输入:</b>n = 1, m = 1, hBars = [2], vBars = [2]
<b>输出:</b>4
<b>解释:</b>左边的图是一开始的网格图。
横线编号的范围是区间 [1,3] ,竖线编号的范围是区间 [1,3] 。
可以移除的横线段为 [2] ,竖线段为 [2] 。
一种得到最大正方形面积的方法是移除横线段 2 和竖线段 2 。
操作后得到的网格图如右图所示。
正方形空洞面积为 4。
无法得到面积大于 4 的正方形空洞。
所以答案为 4 。
</pre>
<p><strong class="example">示例 3</strong></p>
<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>
<pre>
<b>输入:</b>n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
<b>输出:</b>9
<b>解释:</b>左边的图是一开始的网格图。
横线编号的范围是区间 [1,4] ,竖线编号的范围是区间 [1,5] 。
可以移除的横线段为 [2,3] ,竖线段为 [2,3,4] 。
一种得到最大正方形面积的方法是移除横线段 2、3 和竖线段 3、4 。
操作后得到的网格图如右图所示。
正方形空洞面积为 9。
无法得到面积大于 9 的正方形空洞。
所以答案为 9 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= hBars.length &lt;= 100</code></li>
<li><code>2 &lt;= hBars[i] &lt;= n + 1</code></li>
<li><code>1 &lt;= vBars.length &lt;= 100</code></li>
<li><code>2 &lt;= vBars[i] &lt;= m + 1</code></li>
<li><code>hBars</code>&nbsp;中的值互不相同。</li>
<li><code>vBars</code> 中的值互不相同。</li>
</ul>

@ -0,0 +1,42 @@
<p>给你三个整数&nbsp;<code>a</code>&nbsp;<code>b</code>&nbsp;&nbsp;<code>n</code>&nbsp;,请你返回&nbsp;<code>(a XOR x) * (b XOR x)</code>&nbsp;&nbsp;<strong>最大值</strong>&nbsp;<code>x</code>&nbsp;需要满足 <code>0 &lt;= x &lt; 2<sup>n</sup></code></p>
<p>由于答案可能会很大,返回它对&nbsp;<code>10<sup>9 </sup>+ 7</code>&nbsp;<strong>取余</strong>&nbsp;后的结果。</p>
<p><strong>注意</strong><code>XOR</code>&nbsp;是按位异或操作。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>a = 12, b = 5, n = 4
<b>输出:</b>98
<b>解释:</b>当 x = 2 时,(a XOR x) = 14 且 (b XOR x) = 7 。所以,(a XOR x) * (b XOR x) = 98 。
98 是所有满足 0 &lt;= x &lt; 2<sup>n </sup>中 (a XOR x) * (b XOR x) 的最大值。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>a = 6, b = 7 , n = 5
<b>输出:</b>930
<b>解释:</b>当 x = 25 时,(a XOR x) = 31 且 (b XOR x) = 30 。所以,(a XOR x) * (b XOR x) = 930 。
930 是所有满足 0 &lt;= x &lt; 2<sup>n </sup>中 (a XOR x) * (b XOR x) 的最大值。</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>a = 1, b = 6, n = 3
<b>输出:</b>12
<b>解释: </b>当 x = 5 时,(a XOR x) = 4 且 (b XOR x) = 3 。所以,(a XOR x) * (b XOR x) = 12 。
12 是所有满足 0 &lt;= x &lt; 2<sup>n </sup>中 (a XOR x) * (b XOR x) 的最大值。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= a, b &lt; 2<sup>50</sup></code></li>
<li><code>0 &lt;= n &lt;= 50</code></li>
</ul>

@ -0,0 +1,42 @@
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的字符串数组&nbsp;<code>words</code>&nbsp;和一个字符&nbsp;<code>x</code>&nbsp;</p>
<p>请你返回一个 <strong>下标数组</strong>&nbsp;,表示下标在数组中对应的单词包含字符 <code>x</code>&nbsp;</p>
<p><b>注意</b>&nbsp;,返回的数组可以是&nbsp;<strong>任意</strong>&nbsp;顺序。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>words = ["leet","code"], x = "e"
<b>输出:</b>[0,1]
<b>解释:</b>"e" 在两个单词中都出现了:"l<em><strong>ee</strong></em>t" 和 "cod<em><strong>e</strong></em>" 。所以我们返回下标 0 和 1 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>words = ["abc","bcd","aaaa","cbc"], x = "a"
<b>输出:</b>[0,2]
<b>解释:</b>"a" 在 "<em><strong>a</strong></em>bc" 和 "<em><strong>aaaa</strong></em>" 中出现了,所以我们返回下标 0 和 2 。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>words = ["abc","bcd","aaaa","cbc"], x = "z"
<b>输出:</b>[]
<b>解释:</b>"z" 没有在任何单词中出现。所以我们返回空数组。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 50</code></li>
<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
<li><code>x</code>&nbsp;是一个小写英文字母。</li>
<li><code>words[i]</code>&nbsp;只包含小写英文字母。</li>
</ul>

@ -0,0 +1,63 @@
<p>给你一个字符串 <code>s</code> 和一个正整数 <code>k</code></p>
<p><code>vowels</code><code>consonants</code> 分别表示字符串中元音字母和辅音字母的数量。</p>
<p>如果某个字符串满足以下条件,则称其为 <strong>美丽字符串</strong> </p>
<ul>
<li><code>vowels == consonants</code>,即元音字母和辅音字母的数量相等。</li>
<li><code>(vowels * consonants) % k == 0</code>,即元音字母和辅音字母的数量的乘积能被 <code>k</code> 整除。</li>
</ul>
<p>返回字符串 <code>s</code><strong>非空美丽子字符串</strong> 的数量。</p>
<p>子字符串是字符串中的一个连续字符序列。</p>
<p>英语中的<strong> 元音字母 </strong><code>'a'</code><code>'e'</code><code>'i'</code><code>'o'</code><code>'u'</code></p>
<p>英语中的<strong> 辅音字母 </strong>为除了元音字母之外的所有字母。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "baeyh", k = 2
<strong>输出:</strong>2
<strong>解释:</strong>字符串 s 中有 2 个美丽子字符串。
- 子字符串 "b<em><strong>aeyh</strong></em>"vowels = 2["a","e"]consonants = 2["y","h"])。
可以看出字符串 "aeyh" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
- 子字符串 "<em><strong>baey</strong></em>h"vowels = 2["a","e"]consonants = 2["b","y"])。
可以看出字符串 "baey" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
可以证明字符串 s 中只有 2 个美丽子字符串。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "abba", k = 1
<strong>输出:</strong>3
<strong>解释:</strong>字符串 s 中有 3 个美丽子字符串。
- 子字符串 "<strong><em>ab</em></strong>ba"vowels = 1["a"]consonants = 1["b"])。
- 子字符串 "ab<strong><em>ba</em></strong>"vowels = 1["a"]consonants = 1["b"])。
- 子字符串 "<em><strong>abba</strong></em>"vowels = 2["a","a"]consonants = 2["b","b"])。
可以证明字符串 s 中只有 3 个美丽子字符串。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "bcdf", k = 1
<strong>输出:</strong>0
<strong>解释:</strong>字符串 s 中没有美丽子字符串。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> 仅由小写英文字母组成。</li>
</ul>

@ -0,0 +1,63 @@
<p>给你一个字符串 <code>s</code> 和一个正整数 <code>k</code></p>
<p><code>vowels</code><code>consonants</code> 分别表示字符串中元音字母和辅音字母的数量。</p>
<p>如果某个字符串满足以下条件,则称其为 <strong>美丽字符串</strong> </p>
<ul>
<li><code>vowels == consonants</code>,即元音字母和辅音字母的数量相等。</li>
<li><code>(vowels * consonants) % k == 0</code>,即元音字母和辅音字母的数量的乘积能被 <code>k</code> 整除。</li>
</ul>
<p>返回字符串 <code>s</code><strong>非空美丽子字符串</strong> 的数量。</p>
<p>子字符串是字符串中的一个连续字符序列。</p>
<p>英语中的<strong> 元音字母 </strong><code>'a'</code><code>'e'</code><code>'i'</code><code>'o'</code><code>'u'</code></p>
<p>英语中的<strong> 辅音字母 </strong>为除了元音字母之外的所有字母。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "baeyh", k = 2
<strong>输出:</strong>2
<strong>解释:</strong>字符串 s 中有 2 个美丽子字符串。
- 子字符串 "b<em><strong>aeyh</strong></em>"vowels = 2["a","e"]consonants = 2["y","h"])。
可以看出字符串 "aeyh" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
- 子字符串 "<em><strong>baey</strong></em>h"vowels = 2["a","e"]consonants = 2["b","y"])。
可以看出字符串 "baey" 是美丽字符串,因为 vowels == consonants 且 vowels * consonants % k == 0 。
可以证明字符串 s 中只有 2 个美丽子字符串。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "abba", k = 1
<strong>输出:</strong>3
<strong>解释:</strong>字符串 s 中有 3 个美丽子字符串。
- 子字符串 "<strong><em>ab</em></strong>ba"vowels = 1["a"]consonants = 1["b"])。
- 子字符串 "ab<strong><em>ba</em></strong>"vowels = 1["a"]consonants = 1["b"])。
- 子字符串 "<em><strong>abba</strong></em>"vowels = 2["a","a"]consonants = 2["b","b"])。
可以证明字符串 s 中只有 3 个美丽子字符串。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "bcdf", k = 1
<strong>输出:</strong>0
<strong>解释:</strong>字符串 s 中没有美丽子字符串。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> 仅由小写英文字母组成。</li>
</ul>

@ -0,0 +1,50 @@
<p>你在一个水果超市里,货架上摆满了玲琅满目的奇珍异果。</p>
<p>给你一个下标从 <strong>1</strong>&nbsp;开始的数组&nbsp;<code>prices</code>&nbsp;,其中&nbsp;<code>prices[i]</code>&nbsp;表示你购买第 <code>i</code>&nbsp;个水果需要花费的金币数目。</p>
<p>水果超市有如下促销活动:</p>
<ul>
<li>如果你花费 <code>price[i]</code>&nbsp;购买了水果&nbsp;<code>i</code>&nbsp;,那么接下来的 <code>i</code>&nbsp;个水果你都可以免费获得。</li>
</ul>
<p><strong>注意</strong>&nbsp;,即使你&nbsp;<strong>可以</strong>&nbsp;免费获得水果&nbsp;<code>j</code>&nbsp;,你仍然可以花费&nbsp;<code>prices[j]</code>&nbsp;个金币去购买它以便能免费获得接下来的 <code>j</code>&nbsp;个水果。</p>
<p>请你返回获得所有水果所需要的 <strong>最少</strong>&nbsp;金币数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>prices = [3,1,2]
<b>输出:</b>4
<b>解释</b><strong></strong>你可以按如下方法获得所有水果:
- 花 3 个金币购买水果 1 ,然后免费获得水果 2 。
- 花 1 个金币购买水果 2 ,然后免费获得水果 3 。
- 免费获得水果 3 。
注意,虽然你可以免费获得水果 2 ,但你还是花 1 个金币去购买它,因为这样的总花费最少。
购买所有水果需要最少花费 4 个金币。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>prices = [1,10,1,1]
<b>输出:</b>2
<b>解释:</b>你可以按如下方法获得所有水果:
- 花 1 个金币购买水果 1 ,然后免费获得水果 2 。
- 免费获得水果 2 。
- 花 1 个金币购买水果 3 ,然后免费获得水果 4 。
- 免费获得水果 4 。
购买所有水果需要最少花费 2 个金币。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= prices.length &lt;= 1000</code></li>
<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,49 @@
<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>
<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>
<p>Return <em>the <strong>lexicographically smallest array</strong> that can be obtained by performing the operation any number of times</em>.</p>
<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>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,5,3,9,8], limit = 2
<strong>Output:</strong> [1,3,5,8,9]
<strong>Explanation:</strong> Apply the operation 2 times:
- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]
- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]
We cannot obtain a lexicographically smaller array by applying any more operations.
Note that it may be possible to get the same result by doing different operations.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,7,6,18,2,1], limit = 3
<strong>Output:</strong> [1,6,7,18,1,2]
<strong>Explanation:</strong> Apply the operation 3 times:
- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]
- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]
- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]
We cannot obtain a lexicographically smaller array by applying any more operations.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,7,28,19,10], limit = 3
<strong>Output:</strong> [1,7,28,19,10]
<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.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,30 @@
<p>You are given three strings <code>s1</code>, <code>s2</code>, and <code>s3</code>. You have to perform the following operation on these three strings <strong>as many times</strong> as you want<!-- notionvc: b5178de7-3318-4129-b7d9-726b47e90621 -->.</p>
<p>In one operation you can choose one of these three strings such that its length is at least <code>2</code><!-- notionvc: 3342ac46-33c8-4010-aacd-e58678ce31ef --> and delete the <strong>rightmost</strong> character of it.</p>
<p>Return <em>the <strong>minimum</strong> number of operations you need to perform to make the three strings equal if there is a way to make them equal, otherwise, return </em><code>-1</code><em>.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s1 = &quot;abc&quot;, s2 = &quot;abb&quot;, s3 = &quot;ab&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Performing operations on s1 and s2 once will lead to three equal strings.
It can be shown that there is no way to make them equal with less than two operations.</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s1 = &quot;dac&quot;, s2 = &quot;bac&quot;, s3 = &quot;cac&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> Because the leftmost letters<!-- notionvc: 47239f7c-eec1-49f8-af79-c206ec88cb07 --> of s1 and s2 are not equal, they could not be equal after any number of operations. So the answer is -1.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s1.length, s2.length, s3.length &lt;= 100</code></li>
<li><font face="monospace"><code>s1</code>,</font> <code><font face="monospace">s2</font></code><font face="monospace"> and</font> <code><font face="monospace">s3</font></code> consist only of lowercase English letters.</li>
</ul>

@ -0,0 +1,44 @@
<p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two adjacent balls and swap them.</p>
<p>Return <em>the <strong>minimum</strong> number of steps to group all the black balls to the right and all the white balls to the left</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;101&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;011&quot;.
Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;100&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;010&quot;.
- Swap s[1] and s[2], s = &quot;001&quot;.
It can be proven that the minimum number of steps needed is 2.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;0111&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> All the black balls are already grouped to the right.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n == s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

@ -0,0 +1,44 @@
<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>
<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>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
<strong>Output:</strong> true
<strong>Explanation:</strong>
<img alt="" src="https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png" style="width: 500px; height: 117px;" />
Initially, the matrix looks like the first figure.
Second figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.
Third figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.
Therefore, return true.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> mat = [[2,2],[2,2]], k = 3
<strong>Output:</strong> true
<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.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> mat = [[1,2]], k = 1
<strong>Output:</strong> false
<strong>Explanation:</strong> After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= mat.length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>
<li><code>1 &lt;= k &lt;= 50</code></li>
</ul>

@ -0,0 +1,48 @@
<p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i &lt; j</code> and <code>heights[i] &lt; heights[j]</code>.</p>
<p>You are also given another array <code>queries</code> where <code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>. On the <code>i<sup>th</sup></code> query, Alice is in building <code>a<sub>i</sub></code> while Bob is in building <code>b<sub>i</sub></code>.</p>
<p>Return <em>an array</em> <code>ans</code> <em>where</em> <code>ans[i]</code> <em>is <strong>the index of the leftmost building</strong> where Alice and Bob can meet on the</em> <code>i<sup>th</sup></code> <em>query</em>. <em>If Alice and Bob cannot move to a common building on query</em> <code>i</code>, <em>set</em> <code>ans[i]</code> <em>to</em> <code>-1</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
<strong>Output:</strong> [2,5,-1,5,2]
<strong>Explanation:</strong> In the first query, Alice and Bob can move to building 2 since heights[0] &lt; heights[2] and heights[1] &lt; heights[2].
In the second query, Alice and Bob can move to building 5 since heights[0] &lt; heights[5] and heights[3] &lt; heights[5].
In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
In the fourth query, Alice and Bob can move to building 5 since heights[3] &lt; heights[5] and heights[4] &lt; heights[5].
In the fifth query, Alice and Bob are already in the same building.
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
<strong>Output:</strong> [7,6,-1,4,6]
<strong>Explanation:</strong> In the first query, Alice can directly move to Bob&#39;s building since heights[0] &lt; heights[7].
In the second query, Alice and Bob can move to building 6 since heights[3] &lt; heights[6] and heights[5] &lt; heights[6].
In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
In the fourth query, Alice and Bob can move to building 4 since heights[3] &lt; heights[4] and heights[0] &lt; heights[4].
In the fifth query, Alice can directly move to Bob&#39;s building since heights[1] &lt; heights[6].
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= heights.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= heights[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= heights.length - 1</code></li>
</ul>

@ -0,0 +1,46 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>
<p>You can perform any number of operations, where each operation involves selecting a <strong>subarray</strong> of the array and replacing it with the <strong>sum</strong> of its elements. For example, if the given array is <code>[1,3,5,6]</code> and you select subarray <code>[3,5]</code> the array will convert to <code>[1,8,6]</code>.</p>
<p>Return <em>the </em><strong><em>maximum</em></strong><em> length of a </em><strong><em>non-decreasing</em></strong><em> array that can be made after applying operations.</em></p>
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,2,2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> This array with length 3 is not non-decreasing.
We have two ways to make the array length two.
First, choosing subarray [2,2] converts the array to [5,4].
Second, choosing subarray [5,2] converts the array to [7,2].
In these two ways the array is not non-decreasing.
And if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing.
So the answer is 1.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The array is non-decreasing. So the answer is 4.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [4,3,2,6]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.
Because the given array is not non-decreasing, the maximum<!-- notionvc: 3447a505-d1ee-4411-8cae-e52162f53a55 --> possible answer is 3.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,86 @@
<p>There is a grid with <code>n + 2</code> <strong>horizontal</strong> bars and <code>m + 2</code> <strong>vertical</strong> bars, and initially containing <code>1 x 1</code> unit cells.</p>
<p>The bars are <strong>1-indexed</strong>.</p>
<p>You are given the two integers, <code>n</code> and <code>m</code>.</p>
<p>You are also given two integer arrays: <code>hBars</code> and <code>vBars</code>.</p>
<ul>
<li><code>hBars</code> contains <strong>distinct</strong> horizontal bars in the range <code>[2, n + 1]</code>.</li>
<li><code>vBars</code> contains <strong>distinct</strong> vertical bars in the range <code>[2, m + 1]</code>.</li>
</ul>
<p>You are allowed to <strong>remove</strong> bars that satisfy any of the following conditions:</p>
<ul>
<li>If it is a horizontal bar, it must correspond to a value in <code>hBars</code>.</li>
<li>If it is a vertical bar, it must correspond to a value in <code>vBars</code>.</li>
</ul>
<p>Return <em>an integer denoting the <strong>maximum</strong> area of a <strong>square-shaped</strong> hole in the grid after removing some bars (<strong>possibly none</strong>).</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 2, m = 1, hBars = [2,3], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].
It is allowed to remove horizontal bars [2,3] and the vertical bar [2].
One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
It can be shown that it is not possible to get a square hole with an area more than 4.
Hence, the answer is 4.
</pre>
<p><strong class="example">Example 2:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 1, m = 1, hBars = [2], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].
It is allowed to remove the horizontal bar [2] and the vertical bar [2].
To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
Hence, the answer is 4, and it is the maximum possible.
</pre>
<p><strong class="example">Example 3:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
<strong>Output:</strong> 9
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].
It is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].
One way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.
The resulting grid is shown on the right.
The hole has an area of 9.
It can be shown that it is not possible to get a square hole with an area more than 9.
Hence, the answer is 9.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= hBars.length &lt;= 100</code></li>
<li><code>2 &lt;= hBars[i] &lt;= n + 1</code></li>
<li><code>1 &lt;= vBars.length &lt;= 100</code></li>
<li><code>2 &lt;= vBars[i] &lt;= m + 1</code></li>
<li>All values in <code>hBars</code> are distinct.</li>
<li>All values in <code>vBars</code> are distinct.</li>
</ul>

@ -0,0 +1,40 @@
<p>Given three integers <code>a</code>, <code>b</code>, and <code>n</code>, return <em>the <strong>maximum value</strong> of</em> <code>(a XOR x) * (b XOR x)</code> <em>where</em> <code>0 &lt;= x &lt; 2<sup>n</sup></code>.</p>
<p>Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
<p><strong>Note</strong> that <code>XOR</code> is the bitwise XOR operation.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> a = 12, b = 5, n = 4
<strong>Output:</strong> 98
<strong>Explanation:</strong> For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.
It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup><span style="font-size: 10.8333px;">.</span>
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> a = 6, b = 7 , n = 5
<strong>Output:</strong> 930
<strong>Explanation:</strong> For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.
It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup>.</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> a = 1, b = 6, n = 3
<strong>Output:</strong> 12
<strong>Explanation:</strong> For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.
It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup>.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= a, b &lt; 2<sup>50</sup></code></li>
<li><code>0 &lt;= n &lt;= 50</code></li>
</ul>

@ -0,0 +1,40 @@
<p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</strong> order.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;leet&quot;,&quot;code&quot;], x = &quot;e&quot;
<strong>Output:</strong> [0,1]
<strong>Explanation:</strong> &quot;e&quot; occurs in both words: &quot;l<strong><u>ee</u></strong>t&quot;, and &quot;cod<u><strong>e</strong></u>&quot;. Hence, we return indices 0 and 1.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;a&quot;
<strong>Output:</strong> [0,2]
<strong>Explanation:</strong> &quot;a&quot; occurs in &quot;<strong><u>a</u></strong>bc&quot;, and &quot;<u><strong>aaaa</strong></u>&quot;. Hence, we return indices 0 and 2.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;z&quot;
<strong>Output:</strong> []
<strong>Explanation:</strong> &quot;z&quot; does not occur in any of the words. Hence, we return an empty array.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 50</code></li>
<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
<li><code>x</code> is a lowercase English letter.</li>
<li><code>words[i]</code> consists only of lowercase English letters.</li>
</ul>

@ -0,0 +1,61 @@
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * consonants) % k == 0</code>, in other terms the multiplication of <code>vowels</code> and <code>consonants</code> is divisible by <code>k</code>.</li>
</ul>
<p>Return <em>the number of <strong>non-empty beautiful substrings</strong> in the given string</em> <code>s</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Vowel letters</strong> in English are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>.</p>
<p><strong>Consonant letters</strong> in English are every letter except vowels.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;baeyh&quot;, k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 beautiful substrings in the given string.
- Substring &quot;b<u>aeyh</u>&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;y&quot;,&quot;h&quot;]).
You can see that string &quot;aeyh&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
- Substring &quot;<u>baey</u>h&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;b&quot;,&quot;y&quot;]).
You can see that string &quot;baey&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
It can be shown that there are only 2 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;abba&quot;, k = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 beautiful substrings in the given string.
- Substring &quot;<u>ab</u>ba&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;ab<u>ba</u>&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;<u>abba</u>&quot;, vowels = 2 ([&quot;a&quot;,&quot;a&quot;]), consonants = 2 ([&quot;b&quot;,&quot;b&quot;]).
It can be shown that there are only 3 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;bcdf&quot;, k = 1
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no beautiful substrings in the given string.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> consists of only English lowercase letters.</li>
</ul>

@ -0,0 +1,61 @@
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * consonants) % k == 0</code>, in other terms the multiplication of <code>vowels</code> and <code>consonants</code> is divisible by <code>k</code>.</li>
</ul>
<p>Return <em>the number of <strong>non-empty beautiful substrings</strong> in the given string</em> <code>s</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Vowel letters</strong> in English are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>.</p>
<p><strong>Consonant letters</strong> in English are every letter except vowels.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;baeyh&quot;, k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 beautiful substrings in the given string.
- Substring &quot;b<u>aeyh</u>&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;y&quot;,&quot;h&quot;]).
You can see that string &quot;aeyh&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
- Substring &quot;<u>baey</u>h&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;b&quot;,&quot;y&quot;]).
You can see that string &quot;baey&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
It can be shown that there are only 2 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;abba&quot;, k = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 beautiful substrings in the given string.
- Substring &quot;<u>ab</u>ba&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;ab<u>ba</u>&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;<u>abba</u>&quot;, vowels = 2 ([&quot;a&quot;,&quot;a&quot;]), consonants = 2 ([&quot;b&quot;,&quot;b&quot;]).
It can be shown that there are only 3 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;bcdf&quot;, k = 1
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no beautiful substrings in the given string.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> consists of only English lowercase letters.</li>
</ul>

@ -0,0 +1,48 @@
<p>You are at a fruit market with different types of exotic fruits on display.</p>
<p>You are given a <strong>1-indexed</strong> array <code>prices</code>, where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following offer:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[i]</code> coins, you can get the next <code>i</code> fruits for free.</li>
</ul>
<p><strong>Note</strong> that even if you <strong>can</strong> take fruit <code>j</code> for free, you can still purchase it for <code>prices[j]</code> coins to receive a new offer.</p>
<p>Return <em>the <strong>minimum</strong> number of coins needed to acquire all the fruits</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> prices = [3,1,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> You can acquire the fruits as follows:
- Purchase the 1<sup>st</sup> fruit with 3 coins, you are allowed to take the 2<sup>nd</sup> fruit for free.
- Purchase the 2<sup>nd</sup> fruit with 1 coin, you are allowed to take the 3<sup>rd</sup> fruit for free.
- Take the 3<sup>rd</sup> fruit for free.
Note that even though you were allowed to take the 2<sup>nd</sup> fruit for free, you purchased it because it is more optimal.
It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> prices = [1,10,1,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> You can acquire the fruits as follows:
- Purchase the 1<sup>st</sup> fruit with 1 coin, you are allowed to take the 2<sup>nd</sup> fruit for free.
- Take the 2<sup>nd</sup> fruit for free.
- Purchase the 3<sup>rd</sup> fruit for 1 coin, you are allowed to take the 4<sup>th</sup> fruit for free.
- Take the 4<sup>t</sup><sup>h</sup> fruit for free.
It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= prices.length &lt;= 1000</code></li>
<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
</ul>

File diff suppressed because it is too large Load Diff

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

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

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,61 @@
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * consonants) % k == 0</code>, in other terms the multiplication of <code>vowels</code> and <code>consonants</code> is divisible by <code>k</code>.</li>
</ul>
<p>Return <em>the number of <strong>non-empty beautiful substrings</strong> in the given string</em> <code>s</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Vowel letters</strong> in English are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>.</p>
<p><strong>Consonant letters</strong> in English are every letter except vowels.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;baeyh&quot;, k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 beautiful substrings in the given string.
- Substring &quot;b<u>aeyh</u>&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;y&quot;,&quot;h&quot;]).
You can see that string &quot;aeyh&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
- Substring &quot;<u>baey</u>h&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;b&quot;,&quot;y&quot;]).
You can see that string &quot;baey&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
It can be shown that there are only 2 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;abba&quot;, k = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 beautiful substrings in the given string.
- Substring &quot;<u>ab</u>ba&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;ab<u>ba</u>&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;<u>abba</u>&quot;, vowels = 2 ([&quot;a&quot;,&quot;a&quot;]), consonants = 2 ([&quot;b&quot;,&quot;b&quot;]).
It can be shown that there are only 3 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;bcdf&quot;, k = 1
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no beautiful substrings in the given string.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 1000</code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> consists of only English lowercase letters.</li>
</ul>

@ -0,0 +1,61 @@
<p>You are given a string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Let <code>vowels</code> and <code>consonants</code> be the number of vowels and consonants in a string.</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li><code>vowels == consonants</code>.</li>
<li><code>(vowels * consonants) % k == 0</code>, in other terms the multiplication of <code>vowels</code> and <code>consonants</code> is divisible by <code>k</code>.</li>
</ul>
<p>Return <em>the number of <strong>non-empty beautiful substrings</strong> in the given string</em> <code>s</code>.</p>
<p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p>
<p><strong>Vowel letters</strong> in English are <code>&#39;a&#39;</code>, <code>&#39;e&#39;</code>, <code>&#39;i&#39;</code>, <code>&#39;o&#39;</code>, and <code>&#39;u&#39;</code>.</p>
<p><strong>Consonant letters</strong> in English are every letter except vowels.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;baeyh&quot;, k = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 beautiful substrings in the given string.
- Substring &quot;b<u>aeyh</u>&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;y&quot;,&quot;h&quot;]).
You can see that string &quot;aeyh&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
- Substring &quot;<u>baey</u>h&quot;, vowels = 2 ([&quot;a&quot;,e&quot;]), consonants = 2 ([&quot;b&quot;,&quot;y&quot;]).
You can see that string &quot;baey&quot; is beautiful as vowels == consonants and vowels * consonants % k == 0.
It can be shown that there are only 2 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;abba&quot;, k = 1
<strong>Output:</strong> 3
<strong>Explanation:</strong> There are 3 beautiful substrings in the given string.
- Substring &quot;<u>ab</u>ba&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;ab<u>ba</u>&quot;, vowels = 1 ([&quot;a&quot;]), consonants = 1 ([&quot;b&quot;]).
- Substring &quot;<u>abba</u>&quot;, vowels = 2 ([&quot;a&quot;,&quot;a&quot;]), consonants = 2 ([&quot;b&quot;,&quot;b&quot;]).
It can be shown that there are only 3 beautiful substrings in the given string.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;bcdf&quot;, k = 1
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no beautiful substrings in the given string.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= k &lt;= 1000</code></li>
<li><code>s</code> consists of only English lowercase letters.</li>
</ul>

@ -0,0 +1,48 @@
<p>You are given a <strong>0-indexed</strong> array <code>heights</code> of positive integers, where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> building.</p>
<p>If a person is in building <code>i</code>, they can move to any other building <code>j</code> if and only if <code>i &lt; j</code> and <code>heights[i] &lt; heights[j]</code>.</p>
<p>You are also given another array <code>queries</code> where <code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code>. On the <code>i<sup>th</sup></code> query, Alice is in building <code>a<sub>i</sub></code> while Bob is in building <code>b<sub>i</sub></code>.</p>
<p>Return <em>an array</em> <code>ans</code> <em>where</em> <code>ans[i]</code> <em>is <strong>the index of the leftmost building</strong> where Alice and Bob can meet on the</em> <code>i<sup>th</sup></code> <em>query</em>. <em>If Alice and Bob cannot move to a common building on query</em> <code>i</code>, <em>set</em> <code>ans[i]</code> <em>to</em> <code>-1</code>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
<strong>Output:</strong> [2,5,-1,5,2]
<strong>Explanation:</strong> In the first query, Alice and Bob can move to building 2 since heights[0] &lt; heights[2] and heights[1] &lt; heights[2].
In the second query, Alice and Bob can move to building 5 since heights[0] &lt; heights[5] and heights[3] &lt; heights[5].
In the third query, Alice cannot meet Bob since Alice cannot move to any other building.
In the fourth query, Alice and Bob can move to building 5 since heights[3] &lt; heights[5] and heights[4] &lt; heights[5].
In the fifth query, Alice and Bob are already in the same building.
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
<strong>Output:</strong> [7,6,-1,4,6]
<strong>Explanation:</strong> In the first query, Alice can directly move to Bob&#39;s building since heights[0] &lt; heights[7].
In the second query, Alice and Bob can move to building 6 since heights[3] &lt; heights[6] and heights[5] &lt; heights[6].
In the third query, Alice cannot meet Bob since Bob cannot move to any other building.
In the fourth query, Alice and Bob can move to building 4 since heights[3] &lt; heights[4] and heights[0] &lt; heights[4].
In the fifth query, Alice can directly move to Bob&#39;s building since heights[1] &lt; heights[6].
For ans[i] != -1, It can be shown that ans[i] is the leftmost building where Alice and Bob can meet.
For ans[i] == -1, It can be shown that there is no building where Alice and Bob can meet.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= heights.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= heights[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>queries[i] = [a<sub>i</sub>, b<sub>i</sub>]</code></li>
<li><code>0 &lt;= a<sub>i</sub>, b<sub>i</sub> &lt;= heights.length - 1</code></li>
</ul>

@ -0,0 +1,46 @@
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>
<p>You can perform any number of operations, where each operation involves selecting a <strong>subarray</strong> of the array and replacing it with the <strong>sum</strong> of its elements. For example, if the given array is <code>[1,3,5,6]</code> and you select subarray <code>[3,5]</code> the array will convert to <code>[1,8,6]</code>.</p>
<p>Return <em>the </em><strong><em>maximum</em></strong><em> length of a </em><strong><em>non-decreasing</em></strong><em> array that can be made after applying operations.</em></p>
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [5,2,2]
<strong>Output:</strong> 1
<strong>Explanation:</strong> This array with length 3 is not non-decreasing.
We have two ways to make the array length two.
First, choosing subarray [2,2] converts the array to [5,4].
Second, choosing subarray [5,2] converts the array to [7,2].
In these two ways the array is not non-decreasing.
And if we choose subarray [5,2,2] and replace it with [9] it becomes non-decreasing.
So the answer is 1.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,3,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The array is non-decreasing. So the answer is 4.
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [4,3,2,6]
<strong>Output:</strong> 3
<strong>Explanation:</strong> Replacing [3,2] with [5] converts the given array to [4,5,6] that is non-decreasing.
Because the given array is not non-decreasing, the maximum<!-- notionvc: 3447a505-d1ee-4411-8cae-e52162f53a55 --> possible answer is 3.</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,40 @@
<p>You are given a <strong>0-indexed</strong> array of strings <code>words</code> and a character <code>x</code>.</p>
<p>Return <em>an <strong>array of indices</strong> representing the words that contain the character </em><code>x</code>.</p>
<p><strong>Note</strong> that the returned array may be in <strong>any</strong> order.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;leet&quot;,&quot;code&quot;], x = &quot;e&quot;
<strong>Output:</strong> [0,1]
<strong>Explanation:</strong> &quot;e&quot; occurs in both words: &quot;l<strong><u>ee</u></strong>t&quot;, and &quot;cod<u><strong>e</strong></u>&quot;. Hence, we return indices 0 and 1.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;a&quot;
<strong>Output:</strong> [0,2]
<strong>Explanation:</strong> &quot;a&quot; occurs in &quot;<strong><u>a</u></strong>bc&quot;, and &quot;<u><strong>aaaa</strong></u>&quot;. Hence, we return indices 0 and 2.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> words = [&quot;abc&quot;,&quot;bcd&quot;,&quot;aaaa&quot;,&quot;cbc&quot;], x = &quot;z&quot;
<strong>Output:</strong> []
<strong>Explanation:</strong> &quot;z&quot; does not occur in any of the words. Hence, we return an empty array.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 50</code></li>
<li><code>1 &lt;= words[i].length &lt;= 50</code></li>
<li><code>x</code> is a lowercase English letter.</li>
<li><code>words[i]</code> consists only of lowercase English letters.</li>
</ul>

@ -0,0 +1,49 @@
<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>
<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>
<p>Return <em>the <strong>lexicographically smallest array</strong> that can be obtained by performing the operation any number of times</em>.</p>
<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>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,5,3,9,8], limit = 2
<strong>Output:</strong> [1,3,5,8,9]
<strong>Explanation:</strong> Apply the operation 2 times:
- Swap nums[1] with nums[2]. The array becomes [1,3,5,9,8]
- Swap nums[3] with nums[4]. The array becomes [1,3,5,8,9]
We cannot obtain a lexicographically smaller array by applying any more operations.
Note that it may be possible to get the same result by doing different operations.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,7,6,18,2,1], limit = 3
<strong>Output:</strong> [1,6,7,18,1,2]
<strong>Explanation:</strong> Apply the operation 3 times:
- Swap nums[1] with nums[2]. The array becomes [1,6,7,18,2,1]
- Swap nums[0] with nums[4]. The array becomes [2,6,7,18,1,1]
- Swap nums[0] with nums[5]. The array becomes [1,6,7,18,1,2]
We cannot obtain a lexicographically smaller array by applying any more operations.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,7,28,19,10], limit = 3
<strong>Output:</strong> [1,7,28,19,10]
<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.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= limit &lt;= 10<sup>9</sup></code></li>
</ul>

@ -0,0 +1,30 @@
<p>You are given three strings <code>s1</code>, <code>s2</code>, and <code>s3</code>. You have to perform the following operation on these three strings <strong>as many times</strong> as you want<!-- notionvc: b5178de7-3318-4129-b7d9-726b47e90621 -->.</p>
<p>In one operation you can choose one of these three strings such that its length is at least <code>2</code><!-- notionvc: 3342ac46-33c8-4010-aacd-e58678ce31ef --> and delete the <strong>rightmost</strong> character of it.</p>
<p>Return <em>the <strong>minimum</strong> number of operations you need to perform to make the three strings equal if there is a way to make them equal, otherwise, return </em><code>-1</code><em>.</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s1 = &quot;abc&quot;, s2 = &quot;abb&quot;, s3 = &quot;ab&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Performing operations on s1 and s2 once will lead to three equal strings.
It can be shown that there is no way to make them equal with less than two operations.</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s1 = &quot;dac&quot;, s2 = &quot;bac&quot;, s3 = &quot;cac&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> Because the leftmost letters<!-- notionvc: 47239f7c-eec1-49f8-af79-c206ec88cb07 --> of s1 and s2 are not equal, they could not be equal after any number of operations. So the answer is -1.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= s1.length, s2.length, s3.length &lt;= 100</code></li>
<li><font face="monospace"><code>s1</code>,</font> <code><font face="monospace">s2</font></code><font face="monospace"> and</font> <code><font face="monospace">s3</font></code> consist only of lowercase English letters.</li>
</ul>

@ -0,0 +1,44 @@
<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>
<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>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2
<strong>Output:</strong> true
<strong>Explanation:</strong>
<img alt="" src="https://assets.leetcode.com/uploads/2023/10/29/similarmatrix.png" style="width: 500px; height: 117px;" />
Initially, the matrix looks like the first figure.
Second figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows.
Third figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix.
Therefore, return true.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> mat = [[2,2],[2,2]], k = 3
<strong>Output:</strong> true
<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.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> mat = [[1,2]], k = 1
<strong>Output:</strong> false
<strong>Explanation:</strong> After one cyclic shift, mat = [[2,1]] which is not equal to the initial matrix. Therefore we return false.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= mat.length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i].length &lt;= 25</code></li>
<li><code>1 &lt;= mat[i][j] &lt;= 25</code></li>
<li><code>1 &lt;= k &lt;= 50</code></li>
</ul>

@ -0,0 +1,86 @@
<p>There is a grid with <code>n + 2</code> <strong>horizontal</strong> bars and <code>m + 2</code> <strong>vertical</strong> bars, and initially containing <code>1 x 1</code> unit cells.</p>
<p>The bars are <strong>1-indexed</strong>.</p>
<p>You are given the two integers, <code>n</code> and <code>m</code>.</p>
<p>You are also given two integer arrays: <code>hBars</code> and <code>vBars</code>.</p>
<ul>
<li><code>hBars</code> contains <strong>distinct</strong> horizontal bars in the range <code>[2, n + 1]</code>.</li>
<li><code>vBars</code> contains <strong>distinct</strong> vertical bars in the range <code>[2, m + 1]</code>.</li>
</ul>
<p>You are allowed to <strong>remove</strong> bars that satisfy any of the following conditions:</p>
<ul>
<li>If it is a horizontal bar, it must correspond to a value in <code>hBars</code>.</li>
<li>If it is a vertical bar, it must correspond to a value in <code>vBars</code>.</li>
</ul>
<p>Return <em>an integer denoting the <strong>maximum</strong> area of a <strong>square-shaped</strong> hole in the grid after removing some bars (<strong>possibly none</strong>).</em></p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 2, m = 1, hBars = [2,3], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,3].
It is allowed to remove horizontal bars [2,3] and the vertical bar [2].
One way to get the maximum square-shaped hole is by removing horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
It can be shown that it is not possible to get a square hole with an area more than 4.
Hence, the answer is 4.
</pre>
<p><strong class="example">Example 2:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 1, m = 1, hBars = [2], vBars = [2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,3], and the vertical bars are in the range [1,3].
It is allowed to remove the horizontal bar [2] and the vertical bar [2].
To get the maximum square-shaped hole, we remove horizontal bar 2 and vertical bar 2.
The resulting grid is shown on the right.
The hole has an area of 4.
Hence, the answer is 4, and it is the maximum possible.
</pre>
<p><strong class="example">Example 3:</strong></p>
<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>
<pre>
<strong>Input:</strong> n = 2, m = 3, hBars = [2,3], vBars = [2,3,4]
<strong>Output:</strong> 9
<strong>Explanation:</strong> The left image shows the initial grid formed by the bars.
The horizontal bars are in the range [1,4], and the vertical bars are in the range [1,5].
It is allowed to remove horizontal bars [2,3] and vertical bars [2,3,4].
One way to get the maximum square-shaped hole is by removing horizontal bars 2 and 3, and vertical bars 3 and 4.
The resulting grid is shown on the right.
The hole has an area of 9.
It can be shown that it is not possible to get a square hole with an area more than 9.
Hence, the answer is 9.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= m &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= hBars.length &lt;= 100</code></li>
<li><code>2 &lt;= hBars[i] &lt;= n + 1</code></li>
<li><code>1 &lt;= vBars.length &lt;= 100</code></li>
<li><code>2 &lt;= vBars[i] &lt;= m + 1</code></li>
<li>All values in <code>hBars</code> are distinct.</li>
<li>All values in <code>vBars</code> are distinct.</li>
</ul>

@ -0,0 +1,40 @@
<p>Given three integers <code>a</code>, <code>b</code>, and <code>n</code>, return <em>the <strong>maximum value</strong> of</em> <code>(a XOR x) * (b XOR x)</code> <em>where</em> <code>0 &lt;= x &lt; 2<sup>n</sup></code>.</p>
<p>Since the answer may be too large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
<p><strong>Note</strong> that <code>XOR</code> is the bitwise XOR operation.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> a = 12, b = 5, n = 4
<strong>Output:</strong> 98
<strong>Explanation:</strong> For x = 2, (a XOR x) = 14 and (b XOR x) = 7. Hence, (a XOR x) * (b XOR x) = 98.
It can be shown that 98 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup><span style="font-size: 10.8333px;">.</span>
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> a = 6, b = 7 , n = 5
<strong>Output:</strong> 930
<strong>Explanation:</strong> For x = 25, (a XOR x) = 31 and (b XOR x) = 30. Hence, (a XOR x) * (b XOR x) = 930.
It can be shown that 930 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup>.</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> a = 1, b = 6, n = 3
<strong>Output:</strong> 12
<strong>Explanation:</strong> For x = 5, (a XOR x) = 4 and (b XOR x) = 3. Hence, (a XOR x) * (b XOR x) = 12.
It can be shown that 12 is the maximum value of (a XOR x) * (b XOR x) for all 0 &lt;= x &lt; 2<sup>n</sup>.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= a, b &lt; 2<sup>50</sup></code></li>
<li><code>0 &lt;= n &lt;= 50</code></li>
</ul>

@ -0,0 +1,48 @@
<p>You are at a fruit market with different types of exotic fruits on display.</p>
<p>You are given a <strong>1-indexed</strong> array <code>prices</code>, where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
<p>The fruit market has the following offer:</p>
<ul>
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[i]</code> coins, you can get the next <code>i</code> fruits for free.</li>
</ul>
<p><strong>Note</strong> that even if you <strong>can</strong> take fruit <code>j</code> for free, you can still purchase it for <code>prices[j]</code> coins to receive a new offer.</p>
<p>Return <em>the <strong>minimum</strong> number of coins needed to acquire all the fruits</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> prices = [3,1,2]
<strong>Output:</strong> 4
<strong>Explanation:</strong> You can acquire the fruits as follows:
- Purchase the 1<sup>st</sup> fruit with 3 coins, you are allowed to take the 2<sup>nd</sup> fruit for free.
- Purchase the 2<sup>nd</sup> fruit with 1 coin, you are allowed to take the 3<sup>rd</sup> fruit for free.
- Take the 3<sup>rd</sup> fruit for free.
Note that even though you were allowed to take the 2<sup>nd</sup> fruit for free, you purchased it because it is more optimal.
It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> prices = [1,10,1,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> You can acquire the fruits as follows:
- Purchase the 1<sup>st</sup> fruit with 1 coin, you are allowed to take the 2<sup>nd</sup> fruit for free.
- Take the 2<sup>nd</sup> fruit for free.
- Purchase the 3<sup>rd</sup> fruit for 1 coin, you are allowed to take the 4<sup>th</sup> fruit for free.
- Take the 4<sup>t</sup><sup>h</sup> fruit for free.
It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= prices.length &lt;= 1000</code></li>
<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
</ul>

@ -0,0 +1,44 @@
<p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>
<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> represent black and white balls, respectively.</p>
<p>In each step, you can choose two adjacent balls and swap them.</p>
<p>Return <em>the <strong>minimum</strong> number of steps to group all the black balls to the right and all the white balls to the left</em>.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;101&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;011&quot;.
Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;100&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can group all the black balls to the right in the following way:
- Swap s[0] and s[1], s = &quot;010&quot;.
- Swap s[1] and s[2], s = &quot;001&quot;.
It can be proven that the minimum number of steps needed is 2.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> s = &quot;0111&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> All the black balls are already grouped to the right.
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= n == s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
</ul>

2
requirements.txt Normal file

@ -0,0 +1,2 @@
requests
bs4