LeetCode weekly contest 141
| Rank | Name | Score | Finish Time | Q1 (4) | Q2 (5) | Q3 (6) | Q4 (8) |
|---|---|---|---|---|---|---|---|
| 234 / 4126 | YoungForest | 22 | 1:18:45 | 0:25:23 1 | 0:36:29 | 0:51:47 | 1:13:45 |
I had a Natural Dialectics exam on Monday and a Matrix exam on Tuesday, but still forced myself to make time for the contest. My review itself was not sufficient, and my usual study was not very solid either. I was really taking things lightly.
To enter the top 200, the finish time had to be at least within 1:14:23.
1089. Duplicate Zeros
Intuition:
Because the requirement is in-place, a natural idea is to update values from back to front.
Two passes: the first forward pass obtains the original coordinate of the last element in the result array.
The second reverse pass updates the result array.
Time complexity: O(N),
Space complexity: O(1).
1 | class Solution { |
I got one penalty because I ignored the case where the final zero is not expanded if there is not enough space.
Test cases:
1 | [0] |
1090. Largest Values From Labels
Intuition:
Greedy idea. Always try to add the item with the largest value.
The concrete implementation is to sort first, and use a hashtable to ensure the use_limit constraint is not violated.
Time complexity: O(N log N),
Space complexity: O(N)
1 | class Solution { |
Test cases:
1 | [5,4,3,2,1] |
1091. Shortest Path in Binary Matrix
Intuition:
For shortest path, use DFS.
Time complexity: O(N^2),
Space complexity: O(N^2).
1 | class Solution { |
My test cases:
1 | [[0,1],[1,0]] |
Expected results:
1 | 2 |
1092. Shortest Common Supersequence
Intuition:
First compute the Longest Common Subsequence.
Then fill in the extra characters.
The template for Longest Common Subsequence is important and needs to be implemented quickly.
Time Complexity: O(str1.size() * str2.size()),
Space Complexity: O(str1.size() * str2.size()).
1 | class Solution { |
My test cases:
1 | "abac" |
Expected results:
1 | "cabac" |