LeetCode weekly contest 188
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (4) | Q3 (5) | Q4 (7) |
|---|---|---|---|---|---|---|---|
| 445 / 12715 | YoungForest | 19 | 1:14:29 | 0:07:04 | 0:17:33 | 0:56:49 | 1:14:29 |
My rating has stayed above 2200 for two weeks. Although this week’s rating has not been updated yet, based on my rank it should continue to rise. I will try to reach the 2300+ line as soon as possible. Recently I have hit a bottleneck in problem solving. I still cannot solve many hard problems, and I have not summarized my own templates and categories for solving problems. I found that many strong people are strong because after seeing the problem statement, they can quickly identify which concrete category the problem belongs to, quickly connect it with problems they have solved before, and only then AC both fast and bug free.
1441. Build an Array With Stack Operations
One pass. Use two indices, one pointing to the position in target, and one pointing to the position in n.
Time complexity: O(max(N, target.size())),
Space complexity: O(N).
1 | class Solution { |
1442. Count Triplets That Can Form Two Arrays of Equal XOR
This problem needs to use one property of XOR. a ^ a = 0, a ^ b = b ^ a, (a ^ b) ^ c = a ^ (b ^ c). That is self-inverse, commutative, and associative.
So we can use an operation similar to prefix sum to calculate the XOR value of an entire interval in O(1).
Then enumerate all triplets and find the ones that satisfy the condition.
Time complexity: O(N ^ 3),
Space complexity: O(N).
1 | class Solution { |
In Discuss, Han Shen gave an
O(N^2) algorithm and an O(N) algorithm.
1443. Minimum Time to Collect All Apples in a Tree
Tree DP. First, recursively search whether all subtrees have apples. Then recursively collect apples in the subtrees.
Time complexity: O(N),
Space complexity: O(N).
At first I misread the problem and ignored that we also had to return to the root node, so I wrote a more complicated tree DP. I added a condition for whether it was necessary to come back. This wasted half an hour. Otherwise my rank in this weekly contest could have been a bit higher.
1 | class Solution { |
1444. Number of Ways of Cutting a Pizza
A typical DP problem.
Each DP step makes one cut.
Time complexity: O(rows * cols * k * (rows + cols)^2),
Space complexity: O(rows * cols * k).
1 | class Solution { |
Postscript
During this month and a half in the cruel problem-solving group, I followed the daily check-ins and solved many fairly hard DP problems. My improvement in weekly contests is also obvious. My ranking in the group went from 30 at the beginning to 15. When I joined, there were 170 people in the group, and now there are only 146. So I suspect many strong people left the group, which made my group ranking look better. But the group members and group owner all encouraged me by saying, “It is you who became stronger.” I think that is indeed part of the reason.
Looking back at my graduate life, I did not do research well, but I did solve quite a few problems. This week I officially passed 1000+ solved problems.
Thinking back to when I saw that LeetCode had more than 1000 problems, I was still sighing: how could anyone ever finish them? Now LeetCode has 1400+ problems, and I have also solved 1000+.