LeetCode biweekly contest 20
| Rank | Name | Score | Finish Time | Q1 (3) | Q2 (4) | Q3 (5) | Q4 (6) |
|---|---|---|---|---|---|---|---|
| 233 / 4347 | YoungForest | 18 | 0:41:39 | 0:03:32 | 0:13:58 1 | 0:24:13 | 0:31:39 1 |
The problems in this contest were relatively simple. It was another contest of speed and bug-free coding.
After missing contests for half a year, I cannot even get into the top 200 in a smaller biweekly contest anymore. Scary.
1356. Sort Integers by The Number of 1 Bits
Use the C++ standard library sorting function and a lambda expression.
Time complexity: O(n log n),
space complexity: O(1).
1 | class Solution { |
1357. Apply Discount Every n Orders
This tests familiarity with data structures. Just implement it directly according to the statement.
Because I did not read carefully, I misunderstood the definition of discount - it means how much to discount, not how much remains - which caused one wrong submission.
Time complexity: O(product.length),
space complexity: O(getBill.length).
1 | class Cashier { |
1358. Number of Substrings Containing All Three Characters
Sliding window. While moving the right side, keep the window minimal. At that point, every substring starting to the left of the window’s left boundary is valid.
Time complexity: O(N),
space complexity: O(1).
1 | class Solution { |
1359. Count All Valid Pickup and Delivery Options
A typical recursive problem.
For n items, choose any one of them as the first pickup, then solve the ordering problem for the remaining n - 1 items. The delivery can be inserted at any position (2 * (n - 1) + 1 possibilities).
A modulo issue caused one Wrong Answer. This is not the first time. I need to be more careful next time.
Time complexity: O(N),
space complexity: O(N) -> O(1), if using an iterative solution or tail recursion. I will not show it here.
1 | class Solution { |