LeetCode Weekly Contest 218
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (4) | Q3 (5) | Q4 (6) |
|---|---|---|---|---|---|---|---|
| 71 / 9827 | YoungForest | 18 | 0:48:21 | 0:03:32 | 0:05:23 | 0:12:14 | 0:43:21 1 |
1678. Goal Parser Interpretation
Warm-up problem. String interpretation. A general approach is to first do lexical analysis to get tokens, then translate them in sequence. Since this problem has few tokens and simple settings, it can be handled in one pass by looking ahead to determine the token.
1 | class Solution { |
Time complexity: O(N),
space complexity: O(N).
It is said that Python contestants solved it in one line.
1679. Max Number of K-Sum Pairs
Greedy. For each number, find its corresponding number and remove it. Use a hash table to store previously seen numbers, so the lookup cost is O(1).
1 | class Solution { |
Time complexity: O(N). The sorting in the code is actually unnecessary; during the contest I did not notice and sorted first.
Space complexity: O(N).
1680. Concatenation of Consecutive Binary Numbers
Straightforward. Use multiplication and addition to simulate concatenation.
One thing to note is whether the left shift operation can directly take modulo. The answer is yes: addition, subtraction, and multiplication can all take modulo directly, but division cannot.
Left shift is equivalent to multiplication.
1 | class Solution { |
Time complexity: O(N * log N),
space complexity: O(1).
1681. Minimum Incompatibility
This problem is labeled medium, but it is worth 6 points, so it is indeed not easy.
The correct approach is state-compression DP; see the discussion section for details. But during the contest, many people ACed it, including me, using a brute-force backtracking solution. Because the time complexity of backtracking + pruning is often hard to analyze, even after it passes, I still do not feel confident.
Especially since LeetCode Weekly Contest recently added a rejudge mechanism, passing during the contest does not necessarily mean success, which makes me even more uneasy.
I first used a greedy idea, always trying to add the smallest number to a set, to obtain a possible solution.
This solution is not necessarily the minimum solution, but it can be used for later pruning.
Then backtracking searches the whole solution space, constructs solution sets, and obtains the minimum solution.
1 | class Solution { |
Time complexity: O((k * log (n / k)) ^ N). Because pruning exists, it runs faster in practice, but the real time complexity is hard to analyze.
Space complexity: O(N).