Skip to content

Commit f1a5421

Browse files
committedMay 24, 2022
update
1 parent f5bf94d commit f1a5421

23 files changed

+12888
-10797
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 力扣题库(完整版)
22

3-
> 最后更新日期: **2022.05.13**
3+
> 最后更新日期: **2022.05.24**
44
>
55
> 使用脚本前请务必仔细完整阅读本 `README.md` 文件
66

‎leetcode-cn/origin-data.json

+6,334-6,250
Large diffs are not rendered by default.

‎leetcode-cn/originData/maximum-bags-with-full-capacity-of-rocks.json

+177
Large diffs are not rendered by default.

‎leetcode-cn/originData/minimum-lines-to-represent-a-line-chart.json

+189
Large diffs are not rendered by default.

‎leetcode-cn/originData/percentage-of-letter-in-string.json

+165
Large diffs are not rendered by default.

‎leetcode-cn/originData/sum-of-total-strength-of-wizards.json

+184
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>给你一个字符串 <code>s</code> 和一个字符 <code>letter</code> ,返回在 <code>s</code> 中等于&nbsp;<code>letter</code>&nbsp;字符所占的 <strong>百分比</strong> ,向下取整到最接近的百分比。</p>
2+
3+
<p>&nbsp;</p>
4+
5+
<p><strong>示例 1:</strong></p>
6+
7+
<pre>
8+
<strong>输入:</strong>s = "foobar", letter = "o"
9+
<strong>输出:</strong>33
10+
<strong>解释:</strong>
11+
等于字母 'o' 的字符在 s 中占到的百分比是 2 / 6 * 100% = 33% ,向下取整,所以返回 33 。
12+
</pre>
13+
14+
<p><strong>示例 2:</strong></p>
15+
16+
<pre>
17+
<strong>输入:</strong>s = "jjjj", letter = "k"
18+
<strong>输出:</strong>0
19+
<strong>解释:</strong>
20+
等于字母 'k' 的字符在 s 中占到的百分比是 0% ,所以返回 0 。</pre>
21+
22+
<p>&nbsp;</p>
23+
24+
<p><strong>提示:</strong></p>
25+
26+
<ul>
27+
<li><code>1 &lt;= s.length &lt;= 100</code></li>
28+
<li><code>s</code> 由小写英文字母组成</li>
29+
<li><code>letter</code> 是一个小写英文字母</li>
30+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<p>作为国王的统治者,你有一支巫师军队听你指挥。</p>
2+
3+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>strength</code>&nbsp;,其中&nbsp;<code>strength[i]</code>&nbsp;表示第&nbsp;<code>i</code>&nbsp;位巫师的力量值。对于连续的一组巫师(也就是这些巫师的力量值是&nbsp;<code>strength</code>&nbsp;的&nbsp;<strong>子数组</strong>),<strong>总力量</strong>&nbsp;定义为以下两个值的&nbsp;<strong>乘积</strong>&nbsp;:</p>
4+
5+
<ul>
6+
<li>巫师中 <strong>最弱</strong>&nbsp;的能力值。</li>
7+
<li>组中所有巫师的个人力量值 <strong>之和</strong>&nbsp;。</li>
8+
</ul>
9+
10+
<p>请你返回 <strong>所有</strong>&nbsp;巫师组的 <strong></strong>&nbsp;力量之和。由于答案可能很大,请将答案对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;<strong>取余</strong>&nbsp;后返回。</p>
11+
12+
<p><strong>子数组</strong>&nbsp;是一个数组里 <strong>非空</strong>&nbsp;连续子序列。</p>
13+
14+
<p>&nbsp;</p>
15+
16+
<p><strong>示例 1:</strong></p>
17+
18+
<pre><b>输入:</b>strength = [1,3,1,2]
19+
<b>输出:</b>44
20+
<b>解释:</b>以下是所有连续巫师组:
21+
- [<em><strong>1</strong></em>,3,1,2] 中 [1] ,总力量值为 min([1]) * sum([1]) = 1 * 1 = 1
22+
- [1,<em><strong>3</strong></em>,1,2] 中 [3] ,总力量值为 min([3]) * sum([3]) = 3 * 3 = 9
23+
- [1,3,<em><strong>1</strong></em>,2] 中 [1] ,总力量值为 min([1]) * sum([1]) = 1 * 1 = 1
24+
- [1,3,1,<em><strong>2</strong></em>] 中 [2] ,总力量值为 min([2]) * sum([2]) = 2 * 2 = 4
25+
- [<em><strong>1,3</strong></em>,1,2] 中 [1,3] ,总力量值为 min([1,3]) * sum([1,3]) = 1 * 4 = 4
26+
- [1,<em><strong>3,1</strong></em>,2] 中 [3,1] ,总力量值为 min([3,1]) * sum([3,1]) = 1 * 4 = 4
27+
- [1,3,<em><strong>1,2</strong></em>] 中 [1,2] ,总力量值为 min([1,2]) * sum([1,2]) = 1 * 3 = 3
28+
- [<em><strong>1,3,1</strong></em>,2] 中 [1,3,1] ,总力量值为 min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
29+
- [1,<em><strong>3,1,2</strong></em>] 中 [3,1,2] ,总力量值为 min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
30+
- [<em><strong>1,3,1,2</strong></em>] 中 [1,3,1,2] ,总力量值为 min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
31+
所有力量值之和为 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44 。
32+
</pre>
33+
34+
<p><strong>示例 2:</strong></p>
35+
36+
<pre><b>输入:</b>strength = [5,4,6]
37+
<b>输出:</b>213
38+
<b>解释:</b>以下是所有连续巫师组:
39+
- [<em><strong>5</strong></em>,4,6] 中 [5] ,总力量值为 min([5]) * sum([5]) = 5 * 5 = 25
40+
- [5,<em><strong>4</strong></em>,6] 中 [4] ,总力量值为 min([4]) * sum([4]) = 4 * 4 = 16
41+
- [5,4,<em><strong>6</strong></em>] 中 [6] ,总力量值为 min([6]) * sum([6]) = 6 * 6 = 36
42+
- [<em><strong>5,4</strong></em>,6] 中 [5,4] ,总力量值为 min([5,4]) * sum([5,4]) = 4 * 9 = 36
43+
- [5,<em><strong>4,6</strong></em>] 中 [4,6] ,总力量值为 min([4,6]) * sum([4,6]) = 4 * 10 = 40
44+
- [<em><strong>5,4,6</strong></em>] 中 [5,4,6] ,总力量值为 min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
45+
所有力量值之和为 25 + 16 + 36 + 36 + 40 + 60 = 213 。
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
50+
<p><strong>提示:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= strength.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>1 &lt;= strength[i] &lt;= 10<sup>9</sup></code></li>
55+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<p>给你一个二维整数数组&nbsp;<code>stockPrices</code> ,其中&nbsp;<code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code>&nbsp;表示股票在&nbsp;<code>day<sub>i</sub></code>&nbsp;的价格为&nbsp;<code>price<sub>i</sub></code>&nbsp;。<strong>折线图</strong>&nbsp;是一个二维平面上的若干个点组成的图,横坐标表示日期,纵坐标表示价格,折线图由相邻的点连接而成。比方说下图是一个例子:</p>
2+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;">
3+
<p>请你返回要表示一个折线图所需要的 <strong>最少线段数</strong>&nbsp;。</p>
4+
5+
<p>&nbsp;</p>
6+
7+
<p><strong>示例 1:</strong></p>
8+
9+
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;"></p>
10+
11+
<pre><b>输入:</b>stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
12+
<b>输出:</b>3
13+
<strong>解释:</strong>
14+
上图为输入对应的图,横坐标表示日期,纵坐标表示价格。
15+
以下 3 个线段可以表示折线图:
16+
- 线段 1 (红色)从 (1,7) 到 (4,4) ,经过 (1,7) ,(2,6) ,(3,5) 和 (4,4) 。
17+
- 线段 2 (蓝色)从 (4,4) 到 (5,4) 。
18+
- 线段 3 (绿色)从 (5,4) 到 (8,1) ,经过 (5,4) ,(6,3) ,(7,2) 和 (8,1) 。
19+
可以证明,无法用少于 3 条线段表示这个折线图。
20+
</pre>
21+
22+
<p><strong>示例 2:</strong></p>
23+
24+
<p><img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;"></p>
25+
26+
<pre><b>输入:</b>stockPrices = [[3,4],[1,2],[7,8],[2,3]]
27+
<b>输出:</b>1
28+
<strong>解释:</strong>
29+
如上图所示,折线图可以用一条线段表示。
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
34+
<p><strong>提示:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= stockPrices.length &lt;= 10<sup>5</sup></code></li>
38+
<li><code>stockPrices[i].length == 2</code></li>
39+
<li><code>1 &lt;= day<sub>i</sub>, price<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
40+
<li>所有&nbsp;<code>day<sub>i</sub></code>&nbsp;<strong>互不相同</strong>&nbsp;。</li>
41+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<p>现有编号从&nbsp;<code>0</code><code>n - 1</code><code>n</code> 个背包。给你两个下标从 <strong>0</strong> 开始的整数数组 <code>capacity</code><code>rocks</code> 。第 <code>i</code> 个背包最大可以装 <code>capacity[i]</code> 块石头,当前已经装了 <code>rocks[i]</code> 块石头。另给你一个整数 <code>additionalRocks</code> ,表示<span class="text-only" data-eleid="10" style="white-space: pre;">你可以放置的额外石头数量,石头可以往 </span><strong><span class="text-only" data-eleid="11" style="white-space: pre;">任意</span></strong><span class="text-only" data-eleid="12" style="white-space: pre;"> 背包中放置。</span></p>
2+
3+
<p>请你将额外的石头放入一些背包中,并返回放置后装满石头的背包的 <strong>最大 </strong>数量<em></em></p>
4+
5+
<p>&nbsp;</p>
6+
7+
<p><strong>示例 1:</strong></p>
8+
9+
<pre>
10+
<strong>输入:</strong>capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
11+
<strong>输出:</strong>3
12+
<strong>解释:</strong>
13+
1 块石头放入背包 0 ,1 块石头放入背包 1 。
14+
每个背包中的石头总数是 [2,3,4,4] 。
15+
背包 0 、背包 1 和 背包 2 都装满石头。
16+
总计 3 个背包装满石头,所以返回 3 。
17+
可以证明不存在超过 3 个背包装满石头的情况。
18+
注意,可能存在其他放置石头的方案同样能够得到 3 这个结果。
19+
</pre>
20+
21+
<p><strong>示例 2:</strong></p>
22+
23+
<pre>
24+
<strong>输入:</strong>capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
25+
<strong>输出:</strong>3
26+
<strong>解释:</strong>
27+
8 块石头放入背包 0 ,2 块石头放入背包 2 。
28+
每个背包中的石头总数是 [10,2,2] 。
29+
背包 0 、背包 1 和背包 2 都装满石头。
30+
总计 3 个背包装满石头,所以返回 3 。
31+
可以证明不存在超过 3 个背包装满石头的情况。
32+
注意,不必用完所有的额外石头。
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>提示:</strong></p>
38+
39+
<ul>
40+
<li><code>n == capacity.length == rocks.length</code></li>
41+
<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
42+
<li><code>1 &lt;= capacity[i] &lt;= 10<sup>9</sup></code></li>
43+
<li><code>0 &lt;= rocks[i] &lt;= capacity[i]</code></li>
44+
<li><code>1 &lt;= additionalRocks &lt;= 10<sup>9</sup></code></li>
45+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<p>Given a string <code>s</code> and a character <code>letter</code>, return<em> the <strong>percentage</strong> of characters in </em><code>s</code><em> that equal </em><code>letter</code><em> <strong>rounded down</strong> to the nearest whole percent.</em></p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong>Example 1:</strong></p>
5+
6+
<pre>
7+
<strong>Input:</strong> s = &quot;foobar&quot;, letter = &quot;o&quot;
8+
<strong>Output:</strong> 33
9+
<strong>Explanation:</strong>
10+
The percentage of characters in s that equal the letter &#39;o&#39; is 2 / 6 * 100% = 33% when rounded down, so we return 33.
11+
</pre>
12+
13+
<p><strong>Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> s = &quot;jjjj&quot;, letter = &quot;k&quot;
17+
<strong>Output:</strong> 0
18+
<strong>Explanation:</strong>
19+
The percentage of characters in s that equal the letter &#39;k&#39; is 0%, so we return 0.</pre>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Constraints:</strong></p>
23+
24+
<ul>
25+
<li><code>1 &lt;= s.length &lt;= 100</code></li>
26+
<li><code>s</code> consists of lowercase English letters.</li>
27+
<li><code>letter</code> is a lowercase English letter.</li>
28+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<p>As the ruler of a kingdom, you have an army of wizards at your command.</p>
2+
3+
<p>You are given a <strong>0-indexed</strong> integer array <code>strength</code>, where <code>strength[i]</code> denotes the strength of the <code>i<sup>th</sup></code> wizard. For a <strong>contiguous</strong> group of wizards (i.e. the wizards&#39; strengths form a <strong>subarray</strong> of <code>strength</code>), the <strong>total strength</strong> is defined as the <strong>product</strong> of the following two values:</p>
4+
5+
<ul>
6+
<li>The strength of the <strong>weakest</strong> wizard in the group.</li>
7+
<li>The <strong>total</strong> of all the individual strengths of the wizards in the group.</li>
8+
</ul>
9+
10+
<p>Return <em>the <strong>sum</strong> of the total strengths of <strong>all</strong> contiguous groups of wizards</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
11+
12+
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong>Example 1:</strong></p>
16+
17+
<pre>
18+
<strong>Input:</strong> strength = [1,3,1,2]
19+
<strong>Output:</strong> 44
20+
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
21+
- [1] from [<u><strong>1</strong></u>,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
22+
- [3] from [1,<u><strong>3</strong></u>,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9
23+
- [1] from [1,3,<u><strong>1</strong></u>,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
24+
- [2] from [1,3,1,<u><strong>2</strong></u>] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4
25+
- [1,3] from [<u><strong>1,3</strong></u>,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4
26+
- [3,1] from [1,<u><strong>3,1</strong></u>,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4
27+
- [1,2] from [1,3,<u><strong>1,2</strong></u>] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3
28+
- [1,3,1] from [<u><strong>1,3,1</strong></u>,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
29+
- [3,1,2] from [1,<u><strong>3,1,2</strong></u>] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
30+
- [1,3,1,2] from [<u><strong>1,3,1,2</strong></u>] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
31+
The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> strength = [5,4,6]
38+
<strong>Output:</strong> 213
39+
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
40+
- [5] from [<u><strong>5</strong></u>,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25
41+
- [4] from [5,<u><strong>4</strong></u>,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16
42+
- [6] from [5,4,<u><strong>6</strong></u>] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36
43+
- [5,4] from [<u><strong>5,4</strong></u>,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36
44+
- [4,6] from [5,<u><strong>4,6</strong></u>] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40
45+
- [5,4,6] from [<u><strong>5,4,6</strong></u>] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
46+
The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= strength.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>1 &lt;= strength[i] &lt;= 10<sup>9</sup></code></li>
55+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<p>You are given a 2D integer array <code>stockPrices</code> where <code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code> indicates the price of the stock on day <code>day<sub>i</sub></code> is <code>price<sub>i</sub></code>. A <strong>line chart</strong> is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:</p>
2+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;" />
3+
<p>Return <em>the <strong>minimum number of lines</strong> needed to represent the line chart</em>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;" />
8+
<pre>
9+
<strong>Input:</strong> stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
10+
<strong>Output:</strong> 3
11+
<strong>Explanation:</strong>
12+
The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
13+
The following 3 lines can be drawn to represent the line chart:
14+
- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
15+
- Line 2 (in blue) from (4,4) to (5,4).
16+
- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
17+
It can be shown that it is not possible to represent the line chart using less than 3 lines.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;" />
22+
<pre>
23+
<strong>Input:</strong> stockPrices = [[3,4],[1,2],[7,8],[2,3]]
24+
<strong>Output:</strong> 1
25+
<strong>Explanation:</strong>
26+
As shown in the diagram above, the line chart can be represented with a single line.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= stockPrices.length &lt;= 10<sup>5</sup></code></li>
34+
<li><code>stockPrices[i].length == 2</code></li>
35+
<li><code>1 &lt;= day<sub>i</sub>, price<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
36+
<li>All <code>day<sub>i</sub></code> are <strong>distinct</strong>.</li>
37+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</code> rocks. You are also given an integer <code>additionalRocks</code>, the number of additional rocks you can place in <strong>any</strong> of the bags.</p>
2+
3+
<p>Return<em> the <strong>maximum</strong> number of bags that could have full capacity after placing the additional rocks in some bags.</em></p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
10+
<strong>Output:</strong> 3
11+
<strong>Explanation:</strong>
12+
Place 1 rock in bag 0 and 1 rock in bag 1.
13+
The number of rocks in each bag are now [2,3,4,4].
14+
Bags 0, 1, and 2 have full capacity.
15+
There are 3 bags at full capacity, so we return 3.
16+
It can be shown that it is not possible to have more than 3 bags at full capacity.
17+
Note that there may be other ways of placing the rocks that result in an answer of 3.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
24+
<strong>Output:</strong> 3
25+
<strong>Explanation:</strong>
26+
Place 8 rocks in bag 0 and 2 rocks in bag 2.
27+
The number of rocks in each bag are now [10,2,2].
28+
Bags 0, 1, and 2 have full capacity.
29+
There are 3 bags at full capacity, so we return 3.
30+
It can be shown that it is not possible to have more than 3 bags at full capacity.
31+
Note that we did not use all of the additional rocks.
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>n == capacity.length == rocks.length</code></li>
39+
<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
40+
<li><code>1 &lt;= capacity[i] &lt;= 10<sup>9</sup></code></li>
41+
<li><code>0 &lt;= rocks[i] &lt;= capacity[i]</code></li>
42+
<li><code>1 &lt;= additionalRocks &lt;= 10<sup>9</sup></code></li>
43+
</ul>

‎leetcode/origin-data.json

+4,638-4,546
Large diffs are not rendered by default.

‎leetcode/originData/maximum-bags-with-full-capacity-of-rocks.json

+174
Large diffs are not rendered by default.

‎leetcode/originData/minimum-lines-to-represent-a-line-chart.json

+186
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"data": {
3+
"question": {
4+
"questionId": "2365",
5+
"questionFrontendId": "2278",
6+
"boundTopicId": null,
7+
"title": "Percentage of Letter in String",
8+
"titleSlug": "percentage-of-letter-in-string",
9+
"content": "<p>Given a string <code>s</code> and a character <code>letter</code>, return<em> the <strong>percentage</strong> of characters in </em><code>s</code><em> that equal </em><code>letter</code><em> <strong>rounded down</strong> to the nearest whole percent.</em></p>\n\n<p>&nbsp;</p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;foobar&quot;, letter = &quot;o&quot;\n<strong>Output:</strong> 33\n<strong>Explanation:</strong>\nThe percentage of characters in s that equal the letter &#39;o&#39; is 2 / 6 * 100% = 33% when rounded down, so we return 33.\n</pre>\n\n<p><strong>Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = &quot;jjjj&quot;, letter = &quot;k&quot;\n<strong>Output:</strong> 0\n<strong>Explanation:</strong>\nThe percentage of characters in s that equal the letter &#39;k&#39; is 0%, so we return 0.</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= s.length &lt;= 100</code></li>\n\t<li><code>s</code> consists of lowercase English letters.</li>\n\t<li><code>letter</code> is a lowercase English letter.</li>\n</ul>\n",
10+
"translatedTitle": null,
11+
"translatedContent": null,
12+
"isPaidOnly": false,
13+
"difficulty": "Easy",
14+
"likes": 79,
15+
"dislikes": 13,
16+
"isLiked": null,
17+
"similarQuestions": "[{\"title\": \"Sort Characters By Frequency\", \"titleSlug\": \"sort-characters-by-frequency\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
18+
"exampleTestcases": "\"foobar\"\n\"o\"\n\"jjjj\"\n\"k\"",
19+
"categoryTitle": "Algorithms",
20+
"contributors": [],
21+
"topicTags": [
22+
{
23+
"name": "String",
24+
"slug": "string",
25+
"translatedName": null,
26+
"__typename": "TopicTagNode"
27+
}
28+
],
29+
"companyTagStats": null,
30+
"codeSnippets": [
31+
{
32+
"lang": "C++",
33+
"langSlug": "cpp",
34+
"code": "class Solution {\npublic:\n int percentageLetter(string s, char letter) {\n \n }\n};",
35+
"__typename": "CodeSnippetNode"
36+
},
37+
{
38+
"lang": "Java",
39+
"langSlug": "java",
40+
"code": "class Solution {\n public int percentageLetter(String s, char letter) {\n \n }\n}",
41+
"__typename": "CodeSnippetNode"
42+
},
43+
{
44+
"lang": "Python",
45+
"langSlug": "python",
46+
"code": "class Solution(object):\n def percentageLetter(self, s, letter):\n \"\"\"\n :type s: str\n :type letter: str\n :rtype: int\n \"\"\"\n ",
47+
"__typename": "CodeSnippetNode"
48+
},
49+
{
50+
"lang": "Python3",
51+
"langSlug": "python3",
52+
"code": "class Solution:\n def percentageLetter(self, s: str, letter: str) -> int:\n ",
53+
"__typename": "CodeSnippetNode"
54+
},
55+
{
56+
"lang": "C",
57+
"langSlug": "c",
58+
"code": "\n\nint percentageLetter(char * s, char letter){\n\n}",
59+
"__typename": "CodeSnippetNode"
60+
},
61+
{
62+
"lang": "C#",
63+
"langSlug": "csharp",
64+
"code": "public class Solution {\n public int PercentageLetter(string s, char letter) {\n \n }\n}",
65+
"__typename": "CodeSnippetNode"
66+
},
67+
{
68+
"lang": "JavaScript",
69+
"langSlug": "javascript",
70+
"code": "/**\n * @param {string} s\n * @param {character} letter\n * @return {number}\n */\nvar percentageLetter = function(s, letter) {\n \n};",
71+
"__typename": "CodeSnippetNode"
72+
},
73+
{
74+
"lang": "Ruby",
75+
"langSlug": "ruby",
76+
"code": "# @param {String} s\n# @param {Character} letter\n# @return {Integer}\ndef percentage_letter(s, letter)\n \nend",
77+
"__typename": "CodeSnippetNode"
78+
},
79+
{
80+
"lang": "Swift",
81+
"langSlug": "swift",
82+
"code": "class Solution {\n func percentageLetter(_ s: String, _ letter: Character) -> Int {\n \n }\n}",
83+
"__typename": "CodeSnippetNode"
84+
},
85+
{
86+
"lang": "Go",
87+
"langSlug": "golang",
88+
"code": "func percentageLetter(s string, letter byte) int {\n \n}",
89+
"__typename": "CodeSnippetNode"
90+
},
91+
{
92+
"lang": "Scala",
93+
"langSlug": "scala",
94+
"code": "object Solution {\n def percentageLetter(s: String, letter: Char): Int = {\n \n }\n}",
95+
"__typename": "CodeSnippetNode"
96+
},
97+
{
98+
"lang": "Kotlin",
99+
"langSlug": "kotlin",
100+
"code": "class Solution {\n fun percentageLetter(s: String, letter: Char): Int {\n \n }\n}",
101+
"__typename": "CodeSnippetNode"
102+
},
103+
{
104+
"lang": "Rust",
105+
"langSlug": "rust",
106+
"code": "impl Solution {\n pub fn percentage_letter(s: String, letter: char) -> i32 {\n \n }\n}",
107+
"__typename": "CodeSnippetNode"
108+
},
109+
{
110+
"lang": "PHP",
111+
"langSlug": "php",
112+
"code": "class Solution {\n\n /**\n * @param String $s\n * @param String $letter\n * @return Integer\n */\n function percentageLetter($s, $letter) {\n \n }\n}",
113+
"__typename": "CodeSnippetNode"
114+
},
115+
{
116+
"lang": "TypeScript",
117+
"langSlug": "typescript",
118+
"code": "function percentageLetter(s: string, letter: string): number {\n\n};",
119+
"__typename": "CodeSnippetNode"
120+
},
121+
{
122+
"lang": "Racket",
123+
"langSlug": "racket",
124+
"code": "(define/contract (percentage-letter s letter)\n (-> string? char? exact-integer?)\n\n )",
125+
"__typename": "CodeSnippetNode"
126+
},
127+
{
128+
"lang": "Erlang",
129+
"langSlug": "erlang",
130+
"code": "-spec percentage_letter(S :: unicode:unicode_binary(), Letter :: char()) -> integer().\npercentage_letter(S, Letter) ->\n .",
131+
"__typename": "CodeSnippetNode"
132+
},
133+
{
134+
"lang": "Elixir",
135+
"langSlug": "elixir",
136+
"code": "defmodule Solution do\n @spec percentage_letter(s :: String.t, letter :: char) :: integer\n def percentage_letter(s, letter) do\n\n end\nend",
137+
"__typename": "CodeSnippetNode"
138+
}
139+
],
140+
"stats": "{\"totalAccepted\": \"17.7K\", \"totalSubmission\": \"24.6K\", \"totalAcceptedRaw\": 17721, \"totalSubmissionRaw\": 24625, \"acRate\": \"72.0%\"}",
141+
"hints": [
142+
"Can we count the number of occurrences of letter in s?",
143+
"Recall that the percentage is calculated as (occurrences / total) * 100."
144+
],
145+
"solution": null,
146+
"status": null,
147+
"sampleTestCase": "\"foobar\"\n\"o\"",
148+
"metaData": "{\n \"name\": \"percentageLetter\",\n \"params\": [\n {\n \"name\": \"s\",\n \"type\": \"string\"\n },\n {\n \"type\": \"character\",\n \"name\": \"letter\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n }\n}",
149+
"judgerAvailable": true,
150+
"judgeType": "large",
151+
"mysqlSchemas": [],
152+
"enableRunCode": true,
153+
"enableTestMode": false,
154+
"enableDebugger": true,
155+
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https://github.com/datastructures-js/queue\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"ruby\": [\"Ruby\", \"<p><code>Ruby 3.1</code></p>\\r\\n\\r\\n<p>Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms</p>\"], \"swift\": [\"Swift\", \"<p><code>Swift 5.5.2</code>.</p>\"], \"golang\": [\"Go\", \"<p><code>Go 1.17.6</code>.</p>\\r\\n\\r\\n<p>Support <a href=\\\"https://godoc.org/github.com/emirpasic/gods\\\" target=\\\"_blank\\\">https://godoc.org/github.com/emirpasic/gods</a> library.</p>\"], \"python3\": [\"Python3\", \"<p><code>Python 3.10</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/3/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/3/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/3/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\"], \"scala\": [\"Scala\", \"<p><code>Scala 2.13.7</code>.</p>\"], \"kotlin\": [\"Kotlin\", \"<p><code>Kotlin 1.3.10</code>.</p>\"], \"rust\": [\"Rust\", \"<p><code>Rust 1.58.1</code></p>\\r\\n\\r\\n<p>Supports <a href=\\\"https://crates.io/crates/rand\\\" target=\\\"_blank\\\">rand </a> v0.6\\u00a0from crates.io</p>\"], \"php\": [\"PHP\", \"<p><code>PHP 8.1</code>.</p>\\r\\n<p>With bcmath module</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"], \"racket\": [\"Racket\", \"<p>Run with <code>Racket 8.3</code>.</p>\"], \"erlang\": [\"Erlang\", \"Erlang/OTP 24.2\"], \"elixir\": [\"Elixir\", \"Elixir 1.13.0 with Erlang/OTP 24.2\"]}",
156+
"libraryUrl": null,
157+
"adminUrl": null,
158+
"challengeQuestion": null,
159+
"__typename": "QuestionNode"
160+
}
161+
}
162+
}

‎leetcode/originData/sum-of-total-strength-of-wizards.json

+181
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<p>You have <code>n</code> bags numbered from <code>0</code> to <code>n - 1</code>. You are given two <strong>0-indexed</strong> integer arrays <code>capacity</code> and <code>rocks</code>. The <code>i<sup>th</sup></code> bag can hold a maximum of <code>capacity[i]</code> rocks and currently contains <code>rocks[i]</code> rocks. You are also given an integer <code>additionalRocks</code>, the number of additional rocks you can place in <strong>any</strong> of the bags.</p>
2+
3+
<p>Return<em> the <strong>maximum</strong> number of bags that could have full capacity after placing the additional rocks in some bags.</em></p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
8+
<pre>
9+
<strong>Input:</strong> capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2
10+
<strong>Output:</strong> 3
11+
<strong>Explanation:</strong>
12+
Place 1 rock in bag 0 and 1 rock in bag 1.
13+
The number of rocks in each bag are now [2,3,4,4].
14+
Bags 0, 1, and 2 have full capacity.
15+
There are 3 bags at full capacity, so we return 3.
16+
It can be shown that it is not possible to have more than 3 bags at full capacity.
17+
Note that there may be other ways of placing the rocks that result in an answer of 3.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100
24+
<strong>Output:</strong> 3
25+
<strong>Explanation:</strong>
26+
Place 8 rocks in bag 0 and 2 rocks in bag 2.
27+
The number of rocks in each bag are now [10,2,2].
28+
Bags 0, 1, and 2 have full capacity.
29+
There are 3 bags at full capacity, so we return 3.
30+
It can be shown that it is not possible to have more than 3 bags at full capacity.
31+
Note that we did not use all of the additional rocks.
32+
</pre>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>n == capacity.length == rocks.length</code></li>
39+
<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
40+
<li><code>1 &lt;= capacity[i] &lt;= 10<sup>9</sup></code></li>
41+
<li><code>0 &lt;= rocks[i] &lt;= capacity[i]</code></li>
42+
<li><code>1 &lt;= additionalRocks &lt;= 10<sup>9</sup></code></li>
43+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<p>You are given a 2D integer array <code>stockPrices</code> where <code>stockPrices[i] = [day<sub>i</sub>, price<sub>i</sub>]</code> indicates the price of the stock on day <code>day<sub>i</sub></code> is <code>price<sub>i</sub></code>. A <strong>line chart</strong> is created from the array by plotting the points on an XY plane with the X-axis representing the day and the Y-axis representing the price and connecting adjacent points. One such example is shown below:</p>
2+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/1920px-pushkin_population_historysvg.png" style="width: 500px; height: 313px;" />
3+
<p>Return <em>the <strong>minimum number of lines</strong> needed to represent the line chart</em>.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong>Example 1:</strong></p>
7+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex0.png" style="width: 400px; height: 400px;" />
8+
<pre>
9+
<strong>Input:</strong> stockPrices = [[1,7],[2,6],[3,5],[4,4],[5,4],[6,3],[7,2],[8,1]]
10+
<strong>Output:</strong> 3
11+
<strong>Explanation:</strong>
12+
The diagram above represents the input, with the X-axis representing the day and Y-axis representing the price.
13+
The following 3 lines can be drawn to represent the line chart:
14+
- Line 1 (in red) from (1,7) to (4,4) passing through (1,7), (2,6), (3,5), and (4,4).
15+
- Line 2 (in blue) from (4,4) to (5,4).
16+
- Line 3 (in green) from (5,4) to (8,1) passing through (5,4), (6,3), (7,2), and (8,1).
17+
It can be shown that it is not possible to represent the line chart using less than 3 lines.
18+
</pre>
19+
20+
<p><strong>Example 2:</strong></p>
21+
<img alt="" src="https://assets.leetcode.com/uploads/2022/03/30/ex1.png" style="width: 325px; height: 325px;" />
22+
<pre>
23+
<strong>Input:</strong> stockPrices = [[3,4],[1,2],[7,8],[2,3]]
24+
<strong>Output:</strong> 1
25+
<strong>Explanation:</strong>
26+
As shown in the diagram above, the line chart can be represented with a single line.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= stockPrices.length &lt;= 10<sup>5</sup></code></li>
34+
<li><code>stockPrices[i].length == 2</code></li>
35+
<li><code>1 &lt;= day<sub>i</sub>, price<sub>i</sub> &lt;= 10<sup>9</sup></code></li>
36+
<li>All <code>day<sub>i</sub></code> are <strong>distinct</strong>.</li>
37+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<p>Given a string <code>s</code> and a character <code>letter</code>, return<em> the <strong>percentage</strong> of characters in </em><code>s</code><em> that equal </em><code>letter</code><em> <strong>rounded down</strong> to the nearest whole percent.</em></p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong>Example 1:</strong></p>
5+
6+
<pre>
7+
<strong>Input:</strong> s = &quot;foobar&quot;, letter = &quot;o&quot;
8+
<strong>Output:</strong> 33
9+
<strong>Explanation:</strong>
10+
The percentage of characters in s that equal the letter &#39;o&#39; is 2 / 6 * 100% = 33% when rounded down, so we return 33.
11+
</pre>
12+
13+
<p><strong>Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> s = &quot;jjjj&quot;, letter = &quot;k&quot;
17+
<strong>Output:</strong> 0
18+
<strong>Explanation:</strong>
19+
The percentage of characters in s that equal the letter &#39;k&#39; is 0%, so we return 0.</pre>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Constraints:</strong></p>
23+
24+
<ul>
25+
<li><code>1 &lt;= s.length &lt;= 100</code></li>
26+
<li><code>s</code> consists of lowercase English letters.</li>
27+
<li><code>letter</code> is a lowercase English letter.</li>
28+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<p>As the ruler of a kingdom, you have an army of wizards at your command.</p>
2+
3+
<p>You are given a <strong>0-indexed</strong> integer array <code>strength</code>, where <code>strength[i]</code> denotes the strength of the <code>i<sup>th</sup></code> wizard. For a <strong>contiguous</strong> group of wizards (i.e. the wizards&#39; strengths form a <strong>subarray</strong> of <code>strength</code>), the <strong>total strength</strong> is defined as the <strong>product</strong> of the following two values:</p>
4+
5+
<ul>
6+
<li>The strength of the <strong>weakest</strong> wizard in the group.</li>
7+
<li>The <strong>total</strong> of all the individual strengths of the wizards in the group.</li>
8+
</ul>
9+
10+
<p>Return <em>the <strong>sum</strong> of the total strengths of <strong>all</strong> contiguous groups of wizards</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>
11+
12+
<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong>Example 1:</strong></p>
16+
17+
<pre>
18+
<strong>Input:</strong> strength = [1,3,1,2]
19+
<strong>Output:</strong> 44
20+
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
21+
- [1] from [<u><strong>1</strong></u>,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
22+
- [3] from [1,<u><strong>3</strong></u>,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9
23+
- [1] from [1,3,<u><strong>1</strong></u>,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1
24+
- [2] from [1,3,1,<u><strong>2</strong></u>] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4
25+
- [1,3] from [<u><strong>1,3</strong></u>,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4
26+
- [3,1] from [1,<u><strong>3,1</strong></u>,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4
27+
- [1,2] from [1,3,<u><strong>1,2</strong></u>] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3
28+
- [1,3,1] from [<u><strong>1,3,1</strong></u>,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5
29+
- [3,1,2] from [1,<u><strong>3,1,2</strong></u>] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6
30+
- [1,3,1,2] from [<u><strong>1,3,1,2</strong></u>] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7
31+
The sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> strength = [5,4,6]
38+
<strong>Output:</strong> 213
39+
<strong>Explanation:</strong> The following are all the contiguous groups of wizards:
40+
- [5] from [<u><strong>5</strong></u>,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25
41+
- [4] from [5,<u><strong>4</strong></u>,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16
42+
- [6] from [5,4,<u><strong>6</strong></u>] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36
43+
- [5,4] from [<u><strong>5,4</strong></u>,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36
44+
- [4,6] from [5,<u><strong>4,6</strong></u>] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40
45+
- [5,4,6] from [<u><strong>5,4,6</strong></u>] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60
46+
The sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= strength.length &lt;= 10<sup>5</sup></code></li>
54+
<li><code>1 &lt;= strength[i] &lt;= 10<sup>9</sup></code></li>
55+
</ul>

0 commit comments

Comments
 (0)
Please sign in to comment.