LeetCode biweekly contest 1
YoungForest · https://youngforest.github.io/en/2019/06/03/LeetCode-biweekly-contest-1/
On this page · 4 sections
| Rank | Name | Score | Finish Time | Q1 (4) | Q2 (5) | Q3 (6) | Q4 (8) |
|---|---|---|---|---|---|---|---|
| 241 / 983 | YoungForest | 7 | 0:18:23 | 0:09:56 | 0:18:23 | null | null |
LeetCode opened its first biweekly contest, every Saturday night from 10:30 to 12:30. The goal may be to make it easier for students in Europe to participate. The normal weekly contest is usually in the early morning in Europe. With the duration extended to two hours, they can also set harder problems.
Since I had already taken ByteDance’s summer camp written test from 19:00 to 21:30, and that written test was also very hard, with only 30% of the second of three programming questions passed, the later biweekly contest also went badly. My result was not ideal. I only solved two Easy problems.
1055. Fixed Point
Intuition:
Straight forward. One pass.
Time complexity: O(N)
Space complexity: O(1)
1 | class Solution { |
Because array A is sorted in ascending order, we can also use binary search to implement O(log N).
1 | class Solution { |
1056. Index Pairs of a String
Intuition:
The problem is Easy and the data size is also small, so a brute-force solution is enough.
Time complexity: O(words.size() * text.size() * words[i].size()),
Space complexity: O(words.size() * text.size()).
1 | class Solution { |
1066. Campus Bikes II
Because the data size is very small, 1 <= workers.length <= bikes.length <= 10, consider brute-force backtracking.
Time complexity: O(workers.length ^ bikes.length).
Space complexity: O(bikes.length).
Sadly, it timed out.
1 | class Solution { |
After reading Discuss, there are two solutions: priority queue or DP.
1067. Digit Count in Range
First, solve a simpler problem:
Solution
Count the number of digit 1.
1 | int countDigitOne(int n) |
Based on the solution above, it is easy to extend to any digit.
One thing to note is that digit 0 cannot be a leading digit, so it needs special handling.
1 | class Solution { |
Time complexity: O(log N)
Space complexity: O(1)