LeetCode 2021 Spring Contest - Team
| Rank | Name | Score | Finish Time | Q1 (2) | Q2 (4) | Q3 (6) | Q4 (8) | Q5 (9) | Q6(12) |
|---|---|---|---|---|---|---|---|---|---|
| 228 / 781 | 佛系刷题 | 6/41 | 1:00:00 | 0:42:42 | 1:00:00 | null | null | null | null |
I did not participate in the previous LC-CN spring and fall contests, because our lab used to hold group meetings every Saturday afternoon, which perfectly conflicted with the contest time. Now my advisor has changed to holding small group meetings on weekdays and a large group meeting once a month, so I finally had the chance to participate in the 2021 Spring Contest.
On Monday, during the Qingming Festival, I participated in the solo contest. Summary blog here.
On Saturday, I teamed up with Lao Lai and George from the Buddhist Problem-Solving Group and set out in a very Buddhist way. The final result was indeed very Buddhist: we ended after two problems. I solved the first problem, and George solved the second problem, though I provided the idea and helped review + debug. I have to say, competing with two teammates was not as effective as me competing alone. No wonder ACM teams need a long time to build chemistry.
LCP 33. Store Water
A warm-up problem. Although it is Easy, as the first problem of a contest, its difficulty was still quite high.
Observation + brute force.
There are two operations in total: upgrade and store water. Obviously, the store water operations should happen after upgrade.
A naive brute-force method is to enumerate all possible numbers of water-storage operations. The number of upgrades is then determined by that, and we choose the minimum among them. Enumerating the number of water-storage operations also has pruning: try smaller values first, and if it is already larger than the global minimum total count, end directly.
1 | class Solution { |
Time complexity: O(max(vat[i]) * buckets.length) = O(10^4 * 100),
space complexity: O(1).
LCP 34. Binary Tree Coloring
DFS. One thing to note is that because the number of nodes in the blue connected component is k, we need to enumerate how the remaining number of blue nodes at the current node is distributed to the left and right subtrees. Also, observing that k is actually small, only 10, further confirmed my guess.
1 | # Definition for a binary tree node. |
Time complexity: O(number of nodes * k),
space complexity: O(number of nodes * k).