Skip to content

Commit 7043fa6

Browse files
authored
feat: add new lc problems: No.3050~3060 (#2381)
1 parent 27ddab1 commit 7043fa6

File tree

28 files changed

+1892
-0
lines changed

28 files changed

+1892
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [3050. Pizza Toppings Cost Analysis](https://leetcode.cn/problems/pizza-toppings-cost-analysis)
2+
3+
[English Version](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>Table: <code><font face="monospace">Toppings</font></code></p>
12+
13+
<pre>
14+
+--------------+---------+
15+
| Column Name | Type |
16+
+--------------+---------+
17+
| topping_name | varchar |
18+
| cost | decimal |
19+
+--------------+---------+
20+
topping_name is the primary key for this table.
21+
Each row of this table contains topping name and the cost of the topping.
22+
</pre>
23+
24+
<p>Write a solution to calculate the <strong>total cost</strong> of <strong>all possible <code>3</code>-topping</strong> pizza combinations from a given list of toppings. The total cost of toppings must be <strong>rounded</strong> to <code>2</code> <strong>decimal</strong> places.</p>
25+
26+
<p><strong>Note:</strong></p>
27+
28+
<ul>
29+
<li><strong>Do not</strong> include the pizzas where a topping is <strong>repeated</strong>. For example, &lsquo;Pepperoni, Pepperoni, Onion Pizza&rsquo;.</li>
30+
<li>Toppings <strong>must be</strong> listed in <strong>alphabetical order</strong>. For example, &#39;Chicken, Onions, Sausage&#39;. &#39;Onion, Sausage, Chicken&#39; is not acceptable.</li>
31+
</ul>
32+
33+
<p>Return<em> the result table ordered by total cost in</em> <em><strong>descending</strong></em> <em>order and combination of toppings in <strong>ascending</strong> order.</em></p>
34+
35+
<p>The result format is in the following example.</p>
36+
37+
<p>&nbsp;</p>
38+
<p><strong class="example">Example 1:</strong></p>
39+
40+
<pre>
41+
<strong>Input:</strong>
42+
Toppings table:
43+
+--------------+------+
44+
| topping_name | cost |
45+
+--------------+------+
46+
| Pepperoni | 0.50 |
47+
| Sausage | 0.70 |
48+
| Chicken | 0.55 |
49+
| Extra Cheese | 0.40 |
50+
+--------------+------+
51+
<strong>Output:</strong>
52+
+--------------------------------+------------+
53+
| pizza | total_cost |
54+
+--------------------------------+------------+
55+
| Chicken,Pepperoni,Sausage | 1.75 |
56+
| Chicken,Extra Cheese,Sausage | 1.65 |
57+
| Extra Cheese,Pepperoni,Sausage | 1.60 |
58+
| Chicken,Extra Cheese,Pepperoni | 1.45 |
59+
+--------------------------------+------------+
60+
<strong>Explanation:</strong>
61+
There are only four different combinations possible with the three topings:
62+
- Chicken, Pepperoni, Sausage: Total cost is $1.75 (Chicken $0.55, Pepperoni $0.50, Sausage $0.70).
63+
- Chicken, Extra Cheese, Sausage: Total cost is $1.65 (Chicken $0.55, Extra Cheese $0.40, Sausage $0.70).
64+
- Extra Cheese, Pepperoni, Sausage: Total cost is $1.60 (Extra Cheese $0.40, Pepperoni $0.50, Sausage $0.70).
65+
- Chicken, Extra Cheese, Pepperoni: Total cost is $1.45 (Chicken $0.55, Extra Cheese $0.40, Pepperoni $0.50).
66+
Output table is ordered by the total cost in descending order.</pre>
67+
68+
## 解法
69+
70+
### 方法一
71+
72+
<!-- tabs:start -->
73+
74+
```sql
75+
76+
```
77+
78+
<!-- tabs:end -->
79+
80+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [3050. Pizza Toppings Cost Analysis](https://leetcode.com/problems/pizza-toppings-cost-analysis)
2+
3+
[中文文档](/solution/3000-3099/3050.Pizza%20Toppings%20Cost%20Analysis/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>Table: <code><font face="monospace">Toppings</font></code></p>
10+
11+
<pre>
12+
+--------------+---------+
13+
| Column Name | Type |
14+
+--------------+---------+
15+
| topping_name | varchar |
16+
| cost | decimal |
17+
+--------------+---------+
18+
topping_name is the primary key for this table.
19+
Each row of this table contains topping name and the cost of the topping.
20+
</pre>
21+
22+
<p>Write a solution to calculate the <strong>total cost</strong> of <strong>all possible <code>3</code>-topping</strong> pizza combinations from a given list of toppings. The total cost of toppings must be <strong>rounded</strong> to <code>2</code> <strong>decimal</strong> places.</p>
23+
24+
<p><strong>Note:</strong></p>
25+
26+
<ul>
27+
<li><strong>Do not</strong> include the pizzas where a topping is <strong>repeated</strong>. For example, &lsquo;Pepperoni, Pepperoni, Onion Pizza&rsquo;.</li>
28+
<li>Toppings <strong>must be</strong> listed in <strong>alphabetical order</strong>. For example, &#39;Chicken, Onions, Sausage&#39;. &#39;Onion, Sausage, Chicken&#39; is not acceptable.</li>
29+
</ul>
30+
31+
<p>Return<em> the result table ordered by total cost in</em> <em><strong>descending</strong></em> <em>order and combination of toppings in <strong>ascending</strong> order.</em></p>
32+
33+
<p>The result format is in the following example.</p>
34+
35+
<p>&nbsp;</p>
36+
<p><strong class="example">Example 1:</strong></p>
37+
38+
<pre>
39+
<strong>Input:</strong>
40+
Toppings table:
41+
+--------------+------+
42+
| topping_name | cost |
43+
+--------------+------+
44+
| Pepperoni | 0.50 |
45+
| Sausage | 0.70 |
46+
| Chicken | 0.55 |
47+
| Extra Cheese | 0.40 |
48+
+--------------+------+
49+
<strong>Output:</strong>
50+
+--------------------------------+------------+
51+
| pizza | total_cost |
52+
+--------------------------------+------------+
53+
| Chicken,Pepperoni,Sausage | 1.75 |
54+
| Chicken,Extra Cheese,Sausage | 1.65 |
55+
| Extra Cheese,Pepperoni,Sausage | 1.60 |
56+
| Chicken,Extra Cheese,Pepperoni | 1.45 |
57+
+--------------------------------+------------+
58+
<strong>Explanation:</strong>
59+
There are only four different combinations possible with the three topings:
60+
- Chicken, Pepperoni, Sausage: Total cost is $1.75 (Chicken $0.55, Pepperoni $0.50, Sausage $0.70).
61+
- Chicken, Extra Cheese, Sausage: Total cost is $1.65 (Chicken $0.55, Extra Cheese $0.40, Sausage $0.70).
62+
- Extra Cheese, Pepperoni, Sausage: Total cost is $1.60 (Extra Cheese $0.40, Pepperoni $0.50, Sausage $0.70).
63+
- Chicken, Extra Cheese, Pepperoni: Total cost is $1.45 (Chicken $0.55, Extra Cheese $0.40, Pepperoni $0.50).
64+
Output table is ordered by the total cost in descending order.</pre>
65+
66+
## Solutions
67+
68+
### Solution 1
69+
70+
<!-- tabs:start -->
71+
72+
```sql
73+
74+
```
75+
76+
<!-- tabs:end -->
77+
78+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [3051. Find Candidates for Data Scientist Position](https://leetcode.cn/problems/find-candidates-for-data-scientist-position)
2+
3+
[English Version](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>Table: <font face="monospace"><code>Candidates</code></font></p>
12+
13+
<pre>
14+
+--------------+---------+
15+
| Column Name | Type |
16+
+--------------+---------+
17+
| candidate_id | int |
18+
| skill | varchar |
19+
+--------------+---------+
20+
(candidate_id, skill) is the primary key (columns with unique values) for this table.
21+
Each row includes candidate_id and skill.
22+
</pre>
23+
24+
<p>Write a query to find the <strong>candidates</strong> best suited for a Data Scientist position. The candidate must be proficient in <strong>Python</strong>, <strong>Tableau</strong>, and <strong>PostgreSQL</strong>.</p>
25+
26+
<p>Return <em>the result table ordered by </em><code>candidate_id</code> <em>in <strong>ascending order</strong></em>.</p>
27+
28+
<p>The result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong>
35+
Candidates table:
36+
+---------------+--------------+
37+
| candidate_id | skill |
38+
+---------------+--------------+
39+
| 123 | Python |
40+
| 234 | R |
41+
| 123 | Tableau |
42+
| 123 | PostgreSQL |
43+
| 234 | PowerBI |
44+
| 234 | SQL Server |
45+
| 147 | Python |
46+
| 147 | Tableau |
47+
| 147 | Java |
48+
| 147 | PostgreSQL |
49+
| 256 | Tableau |
50+
| 102 | DataAnalysis |
51+
+---------------+--------------+
52+
<strong>Output:</strong>
53+
+--------------+
54+
| candidate_id |
55+
+--------------+
56+
| 123 |
57+
| 147 |
58+
+--------------+
59+
<strong>Explanation:</strong>
60+
- Candidates 123 and 147 possess the necessary skills in Python, Tableau, and PostgreSQL for the data scientist position.
61+
- Candidates 234 and 102 do not possess any of the required skills for this position.
62+
- Candidate 256 has proficiency in Tableau but is missing skills in Python and PostgreSQL.
63+
The output table is sorted by candidate_id in ascending order.
64+
</pre>
65+
66+
## 解法
67+
68+
### 方法一
69+
70+
<!-- tabs:start -->
71+
72+
```sql
73+
74+
```
75+
76+
<!-- tabs:end -->
77+
78+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# [3051. Find Candidates for Data Scientist Position](https://leetcode.com/problems/find-candidates-for-data-scientist-position)
2+
3+
[中文文档](/solution/3000-3099/3051.Find%20Candidates%20for%20Data%20Scientist%20Position/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>Table: <font face="monospace"><code>Candidates</code></font></p>
10+
11+
<pre>
12+
+--------------+---------+
13+
| Column Name | Type |
14+
+--------------+---------+
15+
| candidate_id | int |
16+
| skill | varchar |
17+
+--------------+---------+
18+
(candidate_id, skill) is the primary key (columns with unique values) for this table.
19+
Each row includes candidate_id and skill.
20+
</pre>
21+
22+
<p>Write a query to find the <strong>candidates</strong> best suited for a Data Scientist position. The candidate must be proficient in <strong>Python</strong>, <strong>Tableau</strong>, and <strong>PostgreSQL</strong>.</p>
23+
24+
<p>Return <em>the result table ordered by </em><code>candidate_id</code> <em>in <strong>ascending order</strong></em>.</p>
25+
26+
<p>The result format is in the following example.</p>
27+
28+
<p>&nbsp;</p>
29+
<p><strong class="example">Example 1:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong>
33+
Candidates table:
34+
+---------------+--------------+
35+
| candidate_id | skill |
36+
+---------------+--------------+
37+
| 123 | Python |
38+
| 234 | R |
39+
| 123 | Tableau |
40+
| 123 | PostgreSQL |
41+
| 234 | PowerBI |
42+
| 234 | SQL Server |
43+
| 147 | Python |
44+
| 147 | Tableau |
45+
| 147 | Java |
46+
| 147 | PostgreSQL |
47+
| 256 | Tableau |
48+
| 102 | DataAnalysis |
49+
+---------------+--------------+
50+
<strong>Output:</strong>
51+
+--------------+
52+
| candidate_id |
53+
+--------------+
54+
| 123 |
55+
| 147 |
56+
+--------------+
57+
<strong>Explanation:</strong>
58+
- Candidates 123 and 147 possess the necessary skills in Python, Tableau, and PostgreSQL for the data scientist position.
59+
- Candidates 234 and 102 do not possess any of the required skills for this position.
60+
- Candidate 256 has proficiency in Tableau but is missing skills in Python and PostgreSQL.
61+
The output table is sorted by candidate_id in ascending order.
62+
</pre>
63+
64+
## Solutions
65+
66+
### Solution 1
67+
68+
<!-- tabs:start -->
69+
70+
```sql
71+
72+
```
73+
74+
<!-- tabs:end -->
75+
76+
<!-- end -->

0 commit comments

Comments
 (0)