LeetCode Weekly Contest 230
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (4) | Q3 (5) | Q4 (7) |
|---|---|---|---|---|---|---|---|
| 314 / 11654 | YoungForest | 12 | 0:27:36 | 0:04:00 | 0:14:38 | 0:27:36 | null |
Since autumn recruitment ended, my enthusiasm for practicing problems and contests has declined day by day.
Previously I did three problems every day, China server, US server, and Cruel. Now I do zero problems a day. Of course, occasionally, when my weekly contest result is not enough to exempt me from check-in, I still need to do one problem per day.
In contrast, contest feedback is still quite strong. In the long term, rating and ranking growth provide motivation. In the short term, Cruel ranking and each contest ranking provide motivation, plus extra points as rewards. Also, after the weekly contest, I can get a red packet in the Cruel group and add a chicken drumstick for myself.
1773. Count Items Matching a Rule
Warm-up problem. Just traverse once according to the problem statement.
1 | class Solution { |
Time complexity: O(N),
space complexity: O(1).
1774. Closest Dessert Cost
Brute force enumeration is enough. Looking at the constraints, both n and m are small, so exponential brute-force search can pass.
You can use only backtracking, or use a ternary bitmask to enumerate.
During the contest I used backtracking.
1 | class Solution { |
Time complexity: O(n * 3 ^ m),
space complexity: O(n * 3 ^ m).
1775. Equal Sum Arrays With Minimum Number of Operations
Greedy. Prioritize the operation with the largest possible change.
1 | class Solution { |
Time complexity: O(nums1.size() + nums2.size()),
space complexity: O(1).
1776. Car Fleet II
A relatively difficult problem. I did not solve it during the contest, but I had some ideas. We can first determine how many fleets the cars will eventually split into. From back to front, by checking whether a car can catch up, not meeting: speed[i] > min of speed [i+1:], the problem can first be divided into several subproblems. Then within each subproblem, maintain a priority queue of collision times to update car states and new collision events. The time complexity is O(N log N).
Later, this idea proved too cumbersome to implement and too error-prone.
Although using a priority queue to record collision events can work, the implementation, especially updating collisions, is very cumbersome.
The elegant solution is a monotonic stack. For details, refer to the group owner’s video.