Skip to content

Commit 2df81f8

Browse files
committed
Updated problem description
1 parent b97b065 commit 2df81f8

File tree

53 files changed

+2522
-63
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2522
-63
lines changed

scripts/concurrency/B/Building H2O/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1117. Building H2O</h3>
2-
<div><p>There are two kinds of threads: <code>oxygen</code> and <code>hydrogen</code>. Your goal is to group these threads to form water molecules.</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>There are two kinds of threads: <code>oxygen</code> and <code>hydrogen</code>. Your goal is to group these threads to form water molecules.</p>
33

44
<p>There is a barrier where each thread has to wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given <code>releaseHydrogen</code> and <code>releaseOxygen</code> methods respectively, which will allow them to pass the barrier. These threads should pass the barrier in groups of three, and they must immediately bond with each other to form a water molecule. You must guarantee that all the threads from one molecule bond before any other threads from the next molecule do.</p>
55

@@ -39,4 +39,4 @@
3939
<li>There will be exactly <code>2 * n</code> <code>'H'</code> in <code>water</code>.</li>
4040
<li>There will be exactly <code>n</code> <code>'O'</code> in <code>water</code>.</li>
4141
</ul>
42-
</div>
42+
</div></div>

scripts/concurrency/F/Fizz Buzz Multithreaded/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1195. Fizz Buzz Multithreaded</h3>
2-
<div><p>You have the four functions:</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>You have the four functions:</p>
33

44
<ul>
55
<li><code>printFizz</code> that prints the word <code>"fizz"</code> to the console,</li>
@@ -50,4 +50,4 @@
5050
<ul>
5151
<li><code>1 &lt;= n &lt;= 50</code></li>
5252
</ul>
53-
</div>
53+
</div></div>

scripts/concurrency/P/Print FooBar Alternately/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1115. Print FooBar Alternately</h3>
2-
<div><p>Suppose you are given the following code:</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>Suppose you are given the following code:</p>
33

44
<pre>class FooBar {
55
public void foo() {
@@ -47,4 +47,4 @@
4747
<ul>
4848
<li><code>1 &lt;= n &lt;= 1000</code></li>
4949
</ul>
50-
</div>
50+
</div></div>

scripts/concurrency/P/Print Zero Even Odd/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1116. Print Zero Even Odd</h3>
2-
<div><p>You have a function <code>printNumber</code> that can be called with an integer parameter and prints it to the console.</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>You have a function <code>printNumber</code> that can be called with an integer parameter and prints it to the console.</p>
33

44
<ul>
55
<li>For example, calling <code>printNumber(7)</code> prints <code>7</code> to the console.</li>
@@ -46,4 +46,4 @@ One of them calls zero(), the other calls even(), and the last one calls odd().
4646
<ul>
4747
<li><code>1 &lt;= n &lt;= 1000</code></li>
4848
</ul>
49-
</div>
49+
</div></div>

scripts/concurrency/P/Print in Order/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1114. Print in Order</h3>
2-
<div><p>Suppose we have a class:</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>Suppose we have a class:</p>
33

44
<pre>public class Foo {
55
public void first() { print("first"); }
@@ -35,4 +35,4 @@
3535
<ul>
3636
<li><code>nums</code> is a permutation of <code>[1, 2, 3]</code>.</li>
3737
</ul>
38-
</div>
38+
</div></div>

scripts/concurrency/T/The Dining Philosophers/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h3 align="left"> 1226. The Dining Philosophers</h3>
2-
<div><p>Five silent philosophers&nbsp;sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.</p>
2+
<div class="content__u3I1 question-content__JfgR"><div><p>Five silent philosophers&nbsp;sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.</p>
33

44
<p>Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.</p>
55

@@ -44,4 +44,4 @@ output[i] = [a, b, c] (three integers)
4444
<ul>
4545
<li><code>1 &lt;= n &lt;= 60</code></li>
4646
</ul>
47-
</div>
47+
</div></div>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
<h3 align="left"> 1050. Actors and Directors Who Cooperated At Least Three Times</h3>
2-
<div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div>
2+
<div class="content__u3I1 question-content__JfgR"><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>ActorDirector</code></p>
3+
4+
<pre>+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| actor_id | int |
8+
| director_id | int |
9+
| timestamp | int |
10+
+-------------+---------+
11+
timestamp is the primary key column for this table.
12+
</pre>
13+
14+
<p>&nbsp;</p>
15+
16+
<p>Write a SQL query for a report that provides the pairs <code>(actor_id, director_id)</code> where the actor has cooperated with the director at least three times.</p>
17+
18+
<p>Return the result table in <strong>any order</strong>.</p>
19+
20+
<p>The query result format is in the following example.</p>
21+
22+
<p>&nbsp;</p>
23+
<p><strong>Example 1:</strong></p>
24+
25+
<pre><strong>Input:</strong>
26+
ActorDirector table:
27+
+-------------+-------------+-------------+
28+
| actor_id | director_id | timestamp |
29+
+-------------+-------------+-------------+
30+
| 1 | 1 | 0 |
31+
| 1 | 1 | 1 |
32+
| 1 | 1 | 2 |
33+
| 1 | 2 | 3 |
34+
| 1 | 2 | 4 |
35+
| 2 | 1 | 5 |
36+
| 2 | 1 | 6 |
37+
+-------------+-------------+-------------+
38+
<strong>Output:</strong>
39+
+-------------+-------------+
40+
| actor_id | director_id |
41+
+-------------+-------------+
42+
| 1 | 1 |
43+
+-------------+-------------+
44+
<strong>Explanation:</strong> The only pair is (1, 1) where they cooperated exactly 3 times.
45+
</pre>
46+
</div></div>
+48-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
<h3 align="left"> 1148. Article Views I</h3>
2-
<div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div>
2+
<div class="content__u3I1 question-content__JfgR"><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>Views</code></p>
3+
4+
<pre>+---------------+---------+
5+
| Column Name | Type |
6+
+---------------+---------+
7+
| article_id | int |
8+
| author_id | int |
9+
| viewer_id | int |
10+
| view_date | date |
11+
+---------------+---------+
12+
There is no primary key for this table, it may have duplicate rows.
13+
Each row of this table indicates that some viewer viewed an article (written by some author) on some date.
14+
Note that equal author_id and viewer_id indicate the same person.
15+
</pre>
16+
17+
<p>&nbsp;</p>
18+
19+
<p>Write an SQL query to find all the authors that viewed at least one of their own articles.</p>
20+
21+
<p>Return the result table sorted by <code>id</code> in ascending order.</p>
22+
23+
<p>The query result format is in the following example.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Example 1:</strong></p>
27+
28+
<pre><strong>Input:</strong>
29+
Views table:
30+
+------------+-----------+-----------+------------+
31+
| article_id | author_id | viewer_id | view_date |
32+
+------------+-----------+-----------+------------+
33+
| 1 | 3 | 5 | 2019-08-01 |
34+
| 1 | 3 | 6 | 2019-08-02 |
35+
| 2 | 7 | 7 | 2019-08-01 |
36+
| 2 | 7 | 6 | 2019-08-02 |
37+
| 4 | 7 | 1 | 2019-07-22 |
38+
| 3 | 4 | 4 | 2019-07-21 |
39+
| 3 | 4 | 4 | 2019-07-21 |
40+
+------------+-----------+-----------+------------+
41+
<strong>Output:</strong>
42+
+------+
43+
| id |
44+
+------+
45+
| 4 |
46+
| 7 |
47+
+------+
48+
</pre>
49+
</div></div>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,76 @@
11
<h3 align="left"> 1587. Bank Account Summary II</h3>
2-
<div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div>
2+
<div class="content__u3I1 question-content__JfgR"><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>Users</code></p>
3+
4+
<pre>+--------------+---------+
5+
| Column Name | Type |
6+
+--------------+---------+
7+
| account | int |
8+
| name | varchar |
9+
+--------------+---------+
10+
account is the primary key for this table.
11+
Each row of this table contains the account number of each user in the bank.
12+
There will be no two users having the same name in the table.
13+
</pre>
14+
15+
<p>&nbsp;</p>
16+
17+
<p>Table: <code>Transactions</code></p>
18+
19+
<pre>+---------------+---------+
20+
| Column Name | Type |
21+
+---------------+---------+
22+
| trans_id | int |
23+
| account | int |
24+
| amount | int |
25+
| transacted_on | date |
26+
+---------------+---------+
27+
trans_id is the primary key for this table.
28+
Each row of this table contains all changes made to all accounts.
29+
amount is positive if the user received money and negative if they transferred money.
30+
All accounts start with a balance of 0.
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
35+
<p>Write an SQL query to report the name and balance of users with a balance higher than <code>10000</code>. The balance of an account is equal to the sum of the amounts of all transactions involving that account.</p>
36+
37+
<p>Return the result table in <strong>any order</strong>.</p>
38+
39+
<p>The query result format is in the following example.</p>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Example 1:</strong></p>
43+
44+
<pre><strong>Input:</strong>
45+
Users table:
46+
+------------+--------------+
47+
| account | name |
48+
+------------+--------------+
49+
| 900001 | Alice |
50+
| 900002 | Bob |
51+
| 900003 | Charlie |
52+
+------------+--------------+
53+
Transactions table:
54+
+------------+------------+------------+---------------+
55+
| trans_id | account | amount | transacted_on |
56+
+------------+------------+------------+---------------+
57+
| 1 | 900001 | 7000 | 2020-08-01 |
58+
| 2 | 900001 | 7000 | 2020-09-01 |
59+
| 3 | 900001 | -3000 | 2020-09-02 |
60+
| 4 | 900002 | 1000 | 2020-09-12 |
61+
| 5 | 900003 | 6000 | 2020-08-07 |
62+
| 6 | 900003 | 6000 | 2020-09-07 |
63+
| 7 | 900003 | -4000 | 2020-09-11 |
64+
+------------+------------+------------+---------------+
65+
<strong>Output:</strong>
66+
+------------+------------+
67+
| name | balance |
68+
+------------+------------+
69+
| Alice | 11000 |
70+
+------------+------------+
71+
<strong>Explanation:</strong>
72+
Alice's balance is (7000 + 7000 - 3000) = 11000.
73+
Bob's balance is 1000.
74+
Charlie's balance is (6000 + 6000 - 4000) = 8000.
75+
</pre>
76+
</div></div>
+53-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
11
<h3 align="left"> 595. Big Countries</h3>
2-
<div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div>
2+
<div class="content__u3I1 question-content__JfgR"><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>World</code></p>
3+
4+
<pre>+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| name | varchar |
8+
| continent | varchar |
9+
| area | int |
10+
| population | int |
11+
| gdp | int |
12+
+-------------+---------+
13+
name is the primary key column for this table.
14+
Each row of this table gives information about the name of a country, the continent to which it belongs, its area, the population, and its GDP value.
15+
</pre>
16+
17+
<p>&nbsp;</p>
18+
19+
<p>A country is <strong>big</strong> if:</p>
20+
21+
<ul>
22+
<li>it has an area of at least&nbsp;three million (i.e., <code>3000000 km<sup>2</sup></code>), or</li>
23+
<li>it has a population of at least&nbsp;twenty-five million (i.e., <code>25000000</code>).</li>
24+
</ul>
25+
26+
<p>Write an SQL query to report the name, population, and area of the <strong>big countries</strong>.</p>
27+
28+
<p>Return the result table in <strong>any order</strong>.</p>
29+
30+
<p>The query result format is in the following example.</p>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Example 1:</strong></p>
34+
35+
<pre><strong>Input:</strong>
36+
World table:
37+
+-------------+-----------+---------+------------+--------------+
38+
| name | continent | area | population | gdp |
39+
+-------------+-----------+---------+------------+--------------+
40+
| Afghanistan | Asia | 652230 | 25500100 | 20343000000 |
41+
| Albania | Europe | 28748 | 2831741 | 12960000000 |
42+
| Algeria | Africa | 2381741 | 37100000 | 188681000000 |
43+
| Andorra | Europe | 468 | 78115 | 3712000000 |
44+
| Angola | Africa | 1246700 | 20609294 | 100990000000 |
45+
+-------------+-----------+---------+------------+--------------+
46+
<strong>Output:</strong>
47+
+-------------+------------+---------+
48+
| name | population | area |
49+
+-------------+------------+---------+
50+
| Afghanistan | 25500100 | 652230 |
51+
| Algeria | 37100000 | 2381741 |
52+
+-------------+------------+---------+
53+
</pre>
54+
</div></div>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
11
<h3 align="left"> 1873. Calculate Special Bonus</h3>
2-
<div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div>
2+
<div class="content__u3I1 question-content__JfgR"><div class="sql-schema-wrapper__3VBi"><a class="sql-schema-link__3cEg">SQL Schema<svg viewBox="0 0 24 24" width="1em" height="1em" class="icon__1Md2"><path fill-rule="evenodd" d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"></path></svg></a></div><div><p>Table: <code>Employees</code></p>
3+
4+
<pre>+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| employee_id | int |
8+
| name | varchar |
9+
| salary | int |
10+
+-------------+---------+
11+
employee_id is the primary key for this table.
12+
Each row of this table indicates the employee ID, employee name, and salary.
13+
</pre>
14+
15+
<p>&nbsp;</p>
16+
17+
<p>Write an SQL query to calculate the bonus of each employee. The bonus of an employee is <code>100%</code> of their salary if the ID of the employee is <strong>an odd number</strong> and <strong>the employee name does not start with the character </strong><code>'M'</code>. The bonus of an employee is <code>0</code> otherwise.</p>
18+
19+
<p>Return the result table ordered by <code>employee_id</code>.</p>
20+
21+
<p>The query result format is in the following example.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
26+
<pre><strong>Input:</strong>
27+
Employees table:
28+
+-------------+---------+--------+
29+
| employee_id | name | salary |
30+
+-------------+---------+--------+
31+
| 2 | Meir | 3000 |
32+
| 3 | Michael | 3800 |
33+
| 7 | Addilyn | 7400 |
34+
| 8 | Juan | 6100 |
35+
| 9 | Kannon | 7700 |
36+
+-------------+---------+--------+
37+
<strong>Output:</strong>
38+
+-------------+-------+
39+
| employee_id | bonus |
40+
+-------------+-------+
41+
| 2 | 0 |
42+
| 3 | 0 |
43+
| 7 | 7400 |
44+
| 8 | 0 |
45+
| 9 | 7700 |
46+
+-------------+-------+
47+
<strong>Explanation:</strong>
48+
The employees with IDs 2 and 8 get 0 bonus because they have an even employee_id.
49+
The employee with ID 3 gets 0 bonus because their name starts with 'M'.
50+
The rest of the employees get a 100% bonus.
51+
</pre>
52+
</div></div>

0 commit comments

Comments
 (0)