How to leetcode
The motivation
A good software developer doesn’t necessarily need to be a good IOer, but in general a good IOer is more likely to be a good software developer. This logic makes coding more and more important in tech interview.
The daily routine
Now I need to review first, review 3 days per day until I can catch the current date. Only do new exercise when I need to refresh the calendar of memoCard.
After that, do 2 days exercise per day. Until I can catch the current date.
After that, 2 new problems daily during workday(preferably in the morning). Then do the revision whenever possible.
The environment
I am currently using leetcode website.
How to leetcode
始终保持匀速前进,既不松懈倦怠,亦不急于求成
定时归纳总结, 按类训练
深度理解人的记忆规律,高频率高效复习
拥抱孤独,过滤外界杂音,平稳心态
The order to solve problems
- Go through LABULADONG 的算法网站 once first.
- 灵神题单
- The Explore is a great place next. Finish all courses.
- Use the daily problem and study plan tool
The steps to tackle one problem
- If no idea at all, just check the hints. No need to wait for 5, 10 minutes
Advance
- Weekly contest, then codeforce
- Watch this video series to learn how to speak the story
Current leetcode blog
Last problem solved
New page.
The problems not solved
1696 and 1425 in 【强化练习】单调队列的通用实现及经典习题
Biweekly Contest 130 t4: 3145 2900
Biweekly Contest 135 t4: 3225 3100
Weekly Contest 409 t4: 3245 3100 pre-requisite: BIT
Biweekly Contest 143 t3: 3348 3200
Weekly Contest 424 t4: 3357 3000
Weekly Contest 427 t4: 3382 2700
Weekly Contest 428 t4: 3389 2940
Biweekly Contest 146 t4: 3395 2800
Biweekly Contest 147 t4: 3410 2900
Weekly Contest 431 t4: 3414 2600
Weekly Contest 432 t4: 3420 2900
Biweekly Contest 148 t3: 3425 2710
Biweekly Contest 148 t4: 3426 2738
Weekly Contest 434 t3: 3434 2100
Weekly Contest 434 t4: 3435 3100
Biweekly Contest 149 t4: 3441 2900
Weekly Contest 435 t3: 3444 2400
Weekly Contest 435 t3: 3445 2700
Weekly Contest 436 t3: 3448 2400
Weekly Contest 436 t4: 3449 2800
Biweekly Contest 150 t3:3454 2700
Biweekly Contest 150 t4: 3455 2400
Weekly Contest 437 t3: 3458 2300
Weekly Contest 437 t4: 3459 2500
Weekly Contest 438 t3: 3463 2400
Weekly Contest 438 t4: 3464 2800
Weekly Contest 439 t3: 3473 2300
Weekly Contest 439 t4: 3474 2500
The problems pending rewrite
CF 1237D
LC 1060
The problems not recorded
N/A
The best way to record the progression
Screenshot the next day’s list
The problems not noted
1 | find source/_posts/ -name "[0-9]*" | xargs grep -L "Hints" |
The problems not tagged
1 | find source/_posts/ -name "[0-9]*" | xargs grep -A 1 "tags" | grep -e "---" |
Notes
String algorithms:
- KMP is to calculate the prefix array, it can be used to calculated the occurrence of pattern in text
- Z function is to calculate the longest common prefix. example: lc 3303, 3388
- Manacher is to calculate the longest palindrome at each index. example: lc 5, 3327
General notes
- reference is much faster due to no copy and initialization
- initialize the array if possible
How to iterate a map(C++20)
1 | for (auto&[k, v] : m) { |
sort(C++20)
1 | ranges::sort(nums) |
get max element(C++20)
1 | ranges::max_element(vector/map) |
make decimal binary
1 | // s is string of a decimal num |
binary search(C++20)
1 | ranges::lower_bound(vector, val); |
get min/max length of a vector of strings(C++20)
1 | minLen = ranges::min(wordDict, {}, &string::length).length(); |
use __lg(n) + 1
to get the number of bits of one number
Stirling number of the second kind: lc 3317
Templates:
String hash:
1 | class Solution { |
BIT/Fenwick tree: LC 307
Segment tree: lc 3165
Digit dp: lc 2376
Digit dp with lower bound and is_num: 1067
pre-calculate number of prime numbers: LC 3233
C++ template
For online GDB
1 |
|
For local debugging:
1 |
|
To compare and run the test
1 | touch input.txt |
1 | g++ main.cpp -std=c++17 -DTEST |