Skip to content

Commit 8eb508f

Browse files
author
Shuo
committed
A: new
1 parent 9c963b5 commit 8eb508f

File tree

20 files changed

+673
-6
lines changed

20 files changed

+673
-6
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1420">1420</span> | [Build Array Where You Can Find The Maximum Exactly K Comparisons](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons "生成数组") | [Go](problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons) | Hard |
66+
| <span id="1419">1419</span> | [Minimum Number of Frogs Croaking](https://leetcode.com/problems/minimum-number-of-frogs-croaking "数青蛙") | [Go](problems/minimum-number-of-frogs-croaking) | Medium |
67+
| <span id="1418">1418</span> | [Display Table of Food Orders in a Restaurant](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant "点菜展示表") | [Go](problems/display-table-of-food-orders-in-a-restaurant) | Medium |
68+
| <span id="1417">1417</span> | [Reformat The String](https://leetcode.com/problems/reformat-the-string "重新格式化字符串") | [Go](problems/reformat-the-string) | Easy |
69+
| <span id="1416">1416</span> | [Restore The Array](https://leetcode.com/problems/restore-the-array "恢复数组") | [Go](problems/restore-the-array) | Hard |
70+
| <span id="1415">1415</span> | [The k-th Lexicographical String of All Happy Strings of Length n](https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n "长度为 n 的开心字符串中字典序第 k 小的字符串") | [Go](problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n) | Medium |
71+
| <span id="1414">1414</span> | [Find the Minimum Number of Fibonacci Numbers Whose Sum Is K](https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k "和为 K 的最少斐波那契数字数目") | [Go](problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k) | Medium |
72+
| <span id="1413">1413</span> | [Minimum Value to Get Positive Step by Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum "逐步求和得到正数的最小值") | [Go](problems/minimum-value-to-get-positive-step-by-step-sum) | Easy |
73+
| <span id="1412">1412</span> | [Find the Quiet Students in All Exams](https://leetcode.com/problems/find-the-quiet-students-in-all-exams) 🔒 | [MySQL](problems/find-the-quiet-students-in-all-exams) | Hard |
6574
| <span id="1411">1411</span> | [Number of Ways to Paint N × 3 Grid](https://leetcode.com/problems/number-of-ways-to-paint-n-3-grid "给 N x 3 网格图涂色的方案数") | [Go](problems/number-of-ways-to-paint-n-3-grid) | Hard |
6675
| <span id="1410">1410</span> | [HTML Entity Parser](https://leetcode.com/problems/html-entity-parser "HTML 实体解析器") | [Go](problems/html-entity-parser) | Medium |
6776
| <span id="1409">1409</span> | [Queries on a Permutation With Key](https://leetcode.com/problems/queries-on-a-permutation-with-key "查询带键的排列") | [Go](problems/queries-on-a-permutation-with-key) | Medium |
6877
| <span id="1408">1408</span> | [String Matching in an Array](https://leetcode.com/problems/string-matching-in-an-array "数组中的字符串匹配") | [Go](problems/string-matching-in-an-array) | Easy |
69-
| <span id="1407">1407</span> | [Top Travellers](https://leetcode.com/problems/top-travellers) 🔒 | [MySQL](problems/top-travellers) | Easy |
78+
| <span id="1407">1407</span> | [Top Travellers](https://leetcode.com/problems/top-travellers "排名靠前的旅行者") 🔒 | [MySQL](problems/top-travellers) | Easy |
7079
| <span id="1406">1406</span> | [Stone Game III](https://leetcode.com/problems/stone-game-iii "石子游戏 III") | [Go](problems/stone-game-iii) | Hard |
7180
| <span id="1405">1405</span> | [Longest Happy String](https://leetcode.com/problems/longest-happy-string "最长快乐字符串") | [Go](problems/longest-happy-string) | Medium |
7281
| <span id="1404">1404</span> | [Number of Steps to Reduce a Number in Binary Representation to One](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one "将二进制表示减到 1 的步骤数") | [Go](problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one) | Medium |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../minimum-number-of-frogs-croaking "Minimum Number of Frogs Croaking")
9+
                
10+
Next >
11+
12+
## [1420. Build Array Where You Can Find The Maximum Exactly K Comparisons (Hard)](https://leetcode.com/problems/build-array-where-you-can-find-the-maximum-exactly-k-comparisons "生成数组")
13+
14+
<p>Given three integers <code>n</code>, <code>m</code> and <code>k</code>. Consider the following algorithm to find the maximum element of an array of positive integers:</p>
15+
<img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/e.png" style="width: 424px; height: 372px;" />
16+
<p>You should build the array arr which has the following properties:</p>
17+
18+
<ul>
19+
<li><code>arr</code> has exactly <code>n</code> integers.</li>
20+
<li><code>1 &lt;= arr[i] &lt;= m</code> where <code>(0 &lt;= i &lt; n)</code>.</li>
21+
<li>After applying the mentioned algorithm to <code>arr</code>, the value <code>search_cost</code> is equal to <code>k</code>.</li>
22+
</ul>
23+
24+
<p>Return <em>the number of ways</em> to build the array <code>arr</code> under the mentioned conditions.&nbsp;As the answer may grow large, the answer&nbsp;<strong>must be</strong>&nbsp;computed modulo&nbsp;<code>10^9 + 7</code>.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> n = 2, m = 3, k = 1
31+
<strong>Output:</strong> 6
32+
<strong>Explanation:</strong> The possible arrays are [1, 1], [2, 1], [2, 2], [3, 1], [3, 2] [3, 3]
33+
</pre>
34+
35+
<p><strong>Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> n = 5, m = 2, k = 3
39+
<strong>Output:</strong> 0
40+
<strong>Explanation:</strong> There are no possible arrays that satisify the mentioned conditions.
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> n = 9, m = 1, k = 1
47+
<strong>Output:</strong> 1
48+
<strong>Explanation:</strong> The only possible array is [1, 1, 1, 1, 1, 1, 1, 1, 1]
49+
</pre>
50+
51+
<p><strong>Example 4:</strong></p>
52+
53+
<pre>
54+
<strong>Input:</strong> n = 50, m = 100, k = 25
55+
<strong>Output:</strong> 34549172
56+
<strong>Explanation:</strong> Don&#39;t forget to compute the answer modulo 1000000007
57+
</pre>
58+
59+
<p><strong>Example 5:</strong></p>
60+
61+
<pre>
62+
<strong>Input:</strong> n = 37, m = 17, k = 7
63+
<strong>Output:</strong> 418930126
64+
</pre>
65+
66+
<p>&nbsp;</p>
67+
<p><strong>Constraints:</strong></p>
68+
69+
<ul>
70+
<li><code>1 &lt;= n &lt;= 50</code></li>
71+
<li><code>1 &lt;= m &lt;= 100</code></li>
72+
<li><code>0 &lt;= k &lt;= n</code></li>
73+
</ul>
74+
75+
### Related Topics
76+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]
77+
78+
### Hints
79+
<details>
80+
<summary>Hint 1</summary>
81+
Use dynamic programming approach. Build dp table where dp[a][b][c] is the number of ways you can start building the array starting from index a where the search_cost = c and the maximum used integer was b.
82+
</details>
83+
84+
<details>
85+
<summary>Hint 2</summary>
86+
Recursively, solve the small sub-problems first. Optimize your answer by stopping the search if you exceeded k changes.
87+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../reformat-the-string "Reformat The String")
9+
                
10+
[Next >](../minimum-number-of-frogs-croaking "Minimum Number of Frogs Croaking")
11+
12+
## [1418. Display Table of Food Orders in a Restaurant (Medium)](https://leetcode.com/problems/display-table-of-food-orders-in-a-restaurant "点菜展示表")
13+
14+
<p>Given&nbsp;the array <code>orders</code>, which represents the orders that customers have done in a restaurant. More specifically&nbsp;<code>orders[i]=[customerName<sub>i</sub>,tableNumber<sub>i</sub>,foodItem<sub>i</sub>]</code> where <code>customerName<sub>i</sub></code> is the name of the customer, <code>tableNumber<sub>i</sub></code>&nbsp;is the table customer sit at, and <code>foodItem<sub>i</sub></code>&nbsp;is the item customer orders.</p>
15+
16+
<p><em>Return the restaurant&#39;s &ldquo;<strong>display table</strong>&rdquo;</em>. The &ldquo;<strong>display table</strong>&rdquo; is a table whose row entries denote how many of each food item each table ordered. The first column is the table number and the remaining columns correspond to each food item in alphabetical order. The first row should be a header whose first column is &ldquo;Table&rdquo;, followed by the names of the food items. Note that the customer names are not part of the table. Additionally, the rows should be sorted in numerically increasing order.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> orders = [[&quot;David&quot;,&quot;3&quot;,&quot;Ceviche&quot;],[&quot;Corina&quot;,&quot;10&quot;,&quot;Beef Burrito&quot;],[&quot;David&quot;,&quot;3&quot;,&quot;Fried Chicken&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Water&quot;],[&quot;Carla&quot;,&quot;5&quot;,&quot;Ceviche&quot;],[&quot;Rous&quot;,&quot;3&quot;,&quot;Ceviche&quot;]]
23+
<strong>Output:</strong> [[&quot;Table&quot;,&quot;Beef Burrito&quot;,&quot;Ceviche&quot;,&quot;Fried Chicken&quot;,&quot;Water&quot;],[&quot;3&quot;,&quot;0&quot;,&quot;2&quot;,&quot;1&quot;,&quot;0&quot;],[&quot;5&quot;,&quot;0&quot;,&quot;1&quot;,&quot;0&quot;,&quot;1&quot;],[&quot;10&quot;,&quot;1&quot;,&quot;0&quot;,&quot;0&quot;,&quot;0&quot;]]
24+
<strong>Explanation:
25+
</strong>The displaying table looks like:
26+
<strong>Table,Beef Burrito,Ceviche,Fried Chicken,Water</strong>
27+
3 ,0 ,2 ,1 ,0
28+
5 ,0 ,1 ,0 ,1
29+
10 ,1 ,0 ,0 ,0
30+
For the table 3: David orders &quot;Ceviche&quot; and &quot;Fried Chicken&quot;, and Rous orders &quot;Ceviche&quot;.
31+
For the table 5: Carla orders &quot;Water&quot; and &quot;Ceviche&quot;.
32+
For the table 10: Corina orders &quot;Beef Burrito&quot;.
33+
</pre>
34+
35+
<p><strong>Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> orders = [[&quot;James&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Ratesh&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Amadeus&quot;,&quot;12&quot;,&quot;Fried Chicken&quot;],[&quot;Adam&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;],[&quot;Brianna&quot;,&quot;1&quot;,&quot;Canadian Waffles&quot;]]
39+
<strong>Output:</strong> [[&quot;Table&quot;,&quot;Canadian Waffles&quot;,&quot;Fried Chicken&quot;],[&quot;1&quot;,&quot;2&quot;,&quot;0&quot;],[&quot;12&quot;,&quot;0&quot;,&quot;3&quot;]]
40+
<strong>Explanation:</strong>
41+
For the table 1: Adam and Brianna order &quot;Canadian Waffles&quot;.
42+
For the table 12: James, Ratesh and Amadeus order &quot;Fried Chicken&quot;.
43+
</pre>
44+
45+
<p><strong>Example 3:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> orders = [[&quot;Laura&quot;,&quot;2&quot;,&quot;Bean Burrito&quot;],[&quot;Jhon&quot;,&quot;2&quot;,&quot;Beef Burrito&quot;],[&quot;Melissa&quot;,&quot;2&quot;,&quot;Soda&quot;]]
49+
<strong>Output:</strong> [[&quot;Table&quot;,&quot;Bean Burrito&quot;,&quot;Beef Burrito&quot;,&quot;Soda&quot;],[&quot;2&quot;,&quot;1&quot;,&quot;1&quot;,&quot;1&quot;]]
50+
</pre>
51+
52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;=&nbsp;orders.length &lt;= 5 * 10^4</code></li>
57+
<li><code>orders[i].length == 3</code></li>
58+
<li><code>1 &lt;= customerName<sub>i</sub>.length, foodItem<sub>i</sub>.length &lt;= 20</code></li>
59+
<li><code>customerName<sub>i</sub></code> and <code>foodItem<sub>i</sub></code> consist of lowercase and uppercase English letters and the space character.</li>
60+
<li><code>tableNumber<sub>i</sub>&nbsp;</code>is a valid integer between <code>1</code> and <code>500</code>.</li>
61+
</ul>
62+
63+
### Related Topics
64+
[[Hash Table](../../tag/hash-table/README.md)]
65+
66+
### Hints
67+
<details>
68+
<summary>Hint 1</summary>
69+
Keep the frequency of all pairs (tableNumber, foodItem) using a hashmap.
70+
</details>
71+
72+
<details>
73+
<summary>Hint 2</summary>
74+
Sort rows by tableNumber and columns by foodItem, then process the resulted table.
75+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../minimum-value-to-get-positive-step-by-step-sum "Minimum Value to Get Positive Step by Step Sum")
9+
                
10+
[Next >](../the-k-th-lexicographical-string-of-all-happy-strings-of-length-n "The k-th Lexicographical String of All Happy Strings of Length n")
11+
12+
## [1414. Find the Minimum Number of Fibonacci Numbers Whose Sum Is K (Medium)](https://leetcode.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k "和为 K 的最少斐波那契数字数目")
13+
14+
<p>Given the number <code>k</code>, <em>return the minimum number of Fibonacci numbers whose sum is equal to </em><code>k</code>, whether a Fibonacci number could be used multiple times.</p>
15+
16+
<p>The Fibonacci numbers are defined as:</p>
17+
18+
<ul>
19+
<li>F<sub>1</sub> = 1</li>
20+
<li>F<sub>2</sub> = 1</li>
21+
<li>F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub> , for n &gt; 2.</li>
22+
</ul>
23+
It is guaranteed that for the given constraints we can always find such fibonacci numbers that sum <code>k</code>.
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> k = 7
29+
<strong>Output:</strong> 2
30+
<strong>Explanation:</strong> The Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ...
31+
For k = 7 we can use 2 + 5 = 7.</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> k = 10
37+
<strong>Output:</strong> 2
38+
<strong>Explanation:</strong> For k = 10 we can use 2 + 8 = 10.
39+
</pre>
40+
41+
<p><strong>Example 3:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> k = 19
45+
<strong>Output:</strong> 3
46+
<strong>Explanation:</strong> For k = 19 we can use 1 + 5 + 13 = 19.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= k &lt;= 10^9</code></li>
54+
</ul>
55+
56+
### Related Topics
57+
[[Greedy](../../tag/greedy/README.md)]
58+
[[Array](../../tag/array/README.md)]
59+
60+
### Hints
61+
<details>
62+
<summary>Hint 1</summary>
63+
Generate all Fibonacci numbers up to the limit (they are few).
64+
</details>
65+
66+
<details>
67+
<summary>Hint 2</summary>
68+
Use greedy solution, taking at every time the greatest Fibonacci number which is smaller than or equal to the current number. Subtract this Fibonacci number from the current number and repeat again the process.
69+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../number-of-ways-to-paint-n-3-grid "Number of Ways to Paint N × 3 Grid")
9+
                
10+
[Next >](../minimum-value-to-get-positive-step-by-step-sum "Minimum Value to Get Positive Step by Step Sum")
11+
12+
## [1412. Find the Quiet Students in All Exams (Hard)](https://leetcode.com/problems/find-the-quiet-students-in-all-exams "")
13+
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Create table If Not Exists Student (student_id int, student_name varchar(30));
2+
Create table If Not Exists Exam (exam_id int, student_id int, score int);
3+
Truncate table Student;
4+
insert into Student (student_id, student_name) values ('1', 'Daniel');
5+
insert into Student (student_id, student_name) values ('2', 'Jade');
6+
insert into Student (student_id, student_name) values ('3', 'Stella');
7+
insert into Student (student_id, student_name) values ('4', 'Jonathan');
8+
insert into Student (student_id, student_name) values ('5', 'Will');
9+
Truncate table Exam;
10+
insert into Exam (exam_id, student_id, score) values ('10', '1', '70');
11+
insert into Exam (exam_id, student_id, score) values ('10', '2', '80');
12+
insert into Exam (exam_id, student_id, score) values ('10', '3', '90');
13+
insert into Exam (exam_id, student_id, score) values ('20', '1', '80');
14+
insert into Exam (exam_id, student_id, score) values ('30', '1', '70');
15+
insert into Exam (exam_id, student_id, score) values ('30', '3', '80');
16+
insert into Exam (exam_id, student_id, score) values ('30', '4', '90');
17+
insert into Exam (exam_id, student_id, score) values ('40', '1', '60');
18+
insert into Exam (exam_id, student_id, score) values ('40', '2', '70');
19+
insert into Exam (exam_id, student_id, score) values ('40', '4', '80');

problems/fizz-buzz/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,3 @@ Return:
3939
]
4040
</pre>
4141
</p>
42-
43-
### Similar Questions
44-
1. [Fizz Buzz Multithreaded](../fizz-buzz-multithreaded) (Medium)

0 commit comments

Comments
 (0)