LeetCode Biweekly Contest 38
YoungForest · https://youngforest.github.io/en/2020/11/01/LeetCode-biweekly-contest-38/
On this page · 4 sections
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (4) | Q3 (5) | Q4 (6) |
|---|---|---|---|---|---|---|---|
| 318 / 7446 | YoungForest | 18 | 1:07:29 | 0:12:38 | 0:16:42 | 0:57:29 2 | 0:41:26 |
5539. Sort Array by Increasing Frequency
Warm-up problem. First count frequencies according to the problem statement, then sort by frequency.
1 | class Solution { |
Time complexity: O(N log N),
space complexity: O(N).
5540. Widest Vertical Area Between Two Points Containing No Points
Although it looks complicated, it is actually just sorting by x and finding the largest gap. The problem statement deliberately made it sound harder and led everyone around in a circle.
1 | class Solution { |
Time complexity: O(N log N),
space complexity: O(N).
5541. Count Substrings That Differ by One Character
This problem is also brute force. But at first I overcomplicated it and thought brute force was N^4, while actually it is N^3. So I skipped it and did the fourth problem first. After coming back, I still tried to use a so-called 25*N^3 algorithm and TLEed twice. After my roommate reminded me, I suddenly realized that it really was brute force.
1 | class Solution { |
Time complexity: O(N^3),
space complexity: O(1).
5542. Number of Ways to Form a Target String Given a Dictionary
Classic DP. dp(begin, i) represents the number of ways to form target[i:] starting from the begin-th character of words.
The state transition equation is:
dp(begin, i) = dp(begin + 1, i + 1) * (the number of times target[i] appears in words[j][begin]) + dp(begin + 1, i)
1 | class Solution: |
Time complexity: O(words.size() * words[0].size() + words[0].size() * target.size()),
space complexity: O(words[0].size() * target.size()).