[leetcode][Python][Concurrency][Medium] 1226. The Dining Philosophers

Description Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers. 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....

<span title='2022-12-24 15:05:27.192 +0000 UTC'>December 24, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;498 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Python][Concurrency][Medium] 1195. Fizz Buzz Multithreaded

Description You have the four functions: printFizz that prints the word "fizz" to the console, printBuzz that prints the word "buzz" to the console, printFizzBuzz that prints the word "fizzbuzz" to the console, and printNumber that prints a given integer to the console. You are given an instance of the class FizzBuzz that has four functions: fizz, buzz, fizzbuzz and number. The same instance of FizzBuzz will be passed to four different threads:...

<span title='2022-12-24 05:25:42.878 +0000 UTC'>December 24, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;532 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Python][Concurrency][Medium] 1115. Print FooBar Alternately

Description Suppose you are given the following code: class FooBar { public void foo() { for (int i = 0; i < n; i++) { print("foo"); } } public void bar() { for (int i = 0; i < n; i++) { print("bar"); } } } The same instance of FooBar will be passed to two different threads: thread A will call foo(), while thread B will call bar(). Modify the given program to output "foobar" n times....

<span title='2022-12-24 04:07:08.369 +0000 UTC'>December 24, 2022</span>&nbsp;·&nbsp;1 分鐘&nbsp;·&nbsp;192 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Python][Concurrency][Medium] 1188. Design Bounded Blocking Queue

Description Implement a thread-safe bounded blocking queue that has the following methods: BoundedBlockingQueue(int capacity) The constructor initializes the queue with a maximum capacity. void enqueue(int element) Adds an element to the front of the queue. If the queue is full, the calling thread is blocked until the queue is no longer full. int dequeue() Returns the element at the rear of the queue and removes it. If the queue is empty, the calling thread is blocked until the queue is no longer empty....

<span title='2022-12-22 07:45:19.754 +0000 UTC'>December 22, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;486 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Python][Concurrency][Medium] 1242. Web Crawler Multithreaded

Description Given a URL startUrl and an interface HtmlParser, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl. Return all URLs obtained by your web crawler in any order. Your crawler should: Start from the page: startUrl Call HtmlParser.getUrls(url) to get all URLs from a webpage of a given URL. Do not crawl the same link twice. Explore only the links that are under the same hostname as startUrl....

<span title='2022-12-22 06:53:34.26 +0000 UTC'>December 22, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;552 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Python][Concurrency][Easy] 1279. Traffic Light Controlled Intersection

Description There is an intersection of two roads. First road is road A where cars travel from North to South in direction 1 and from South to North in direction 2. Second road is road B where cars travel from West to East in direction 3 and from East to West in direction 4. There is a traffic light located on each road before the intersection. A traffic light can either be green or red....

<span title='2022-12-22 03:40:12.749 +0000 UTC'>December 22, 2022</span>&nbsp;·&nbsp;4 分鐘&nbsp;·&nbsp;683 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Database][Hard] 2173. Longest Winning Streak

Description Table: Matches +-------------+------+ | Column Name | Type | +-------------+------+ | player_id | int | | match_day | date | | result | enum | +-------------+------+ (player_id, match_day) is the primary key for this table. Each row of this table contains the ID of a player, the day of the match they played, and the result of that match. The result column is an ENUM type of ('Win', 'Draw', 'Lose')....

<span title='2022-12-18 21:45:21.994 +0000 UTC'>December 18, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;436 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Database][Hard] 2474. Customers With Strictly Increasing Purchases

Description Table: Orders +--------------+------+ | Column Name | Type | +--------------+------+ | order_id | int | | customer_id | int | | order_date | date | | price | int | +--------------+------+ order_id is the primary key for this table. Each row contains the id of an order, the id of customer that ordered it, the date of the order, and its price. Write an SQL query to report the IDs of the customers with the total purchases strictly increasing yearly....

<span title='2022-12-18 21:30:30.719 +0000 UTC'>December 18, 2022</span>&nbsp;·&nbsp;3 分鐘&nbsp;·&nbsp;549 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Database][Hard] 2362. Generate the Invoice

Description Table: Products +-------------+------+ | Column Name | Type | +-------------+------+ | product_id | int | | price | int | +-------------+------+ product_id is the primary key for this table. Each row in this table shows the ID of a product and the price of one unit. Table: Purchases +-------------+------+ | Column Name | Type | +-------------+------+ | invoice_id | int | | product_id | int | | quantity | int | +-------------+------+ (invoice_id, product_id) is the primary key for this table....

<span title='2022-12-18 21:10:22.259 +0000 UTC'>December 18, 2022</span>&nbsp;·&nbsp;2 分鐘&nbsp;·&nbsp;386 字&nbsp;·&nbsp;ZhengWei, Liu

[leetcode][Database][Hard] 2199. Finding the Topic of Each Post

Description Table: Keywords +-------------+---------+ | Column Name | Type | +-------------+---------+ | topic_id | int | | word | varchar | +-------------+---------+ (topic_id, word) is the primary key for this table. Each row of this table contains the id of a topic and a word that is used to express this topic. There may be more than one word to express the same topic and one word may be used to express multiple topics....

<span title='2022-12-18 20:54:39.019 +0000 UTC'>December 18, 2022</span>&nbsp;·&nbsp;4 分鐘&nbsp;·&nbsp;700 字&nbsp;·&nbsp;ZhengWei, Liu