
SWE, #rust, Competitive Programmer. I am simply the best. β¨Github: https://teapaw.org/t.co/5KKcJ34VEv β¨Codeforces: https://teapaw.org/t.co/uYYkeQXauq
Online
Joined September 2019
- Tweets1.4K
- Following482
- Followers280
- Likes3.3K
Day #100 of #100DaysOfRust, all good things come to an end π§΅
The final boss, the multithreaded web server
βGit: github.com/DreadedHippy/multβ¦
Some time this year, I felt serverely lacking and decided to sharpen my DSA skills.
I stumbled across @fireship_dev 's Rust in 100 seconds
1
19
1,573
Today's Leetcode
Keys:
1. Sort the array
2. dp[i][0]: max j >= i when nums[i] is unmodified
3. dp[i][1]: modified case
4. Pull DP: dp[i] depends on dp[i+1].
6. It is sometimes optimal to skip an element
7. Simulate skipping by ...
1
10
233
Woah, my solution to today's leetcode has a runtime of 15ms, and the leaderboard starts at 50ms.
I looked into it and it seems my solution is faster than the editorial's π (See image 2, my solution is second)
2
6
453
Today's Leetcode:
Keys:
1. Consider "changing" an element as "deleting" it. The idea behind that can be seen in image 3.
2. It is optimal to delete the 2 lowest numbers, 2 highest numbers, or the highest and the lowest numbers.
3. You can sort or track max and min and calculate
Today's Leetcode:
Keys:
1. Iterate only odd indices
2. Count how many indices i such that s[i] != s[i-1]
7
290
Today's Leetcode: Precomputation + Factorization + DP
Resorted to editorial.π
Keys:
1. Precompute factors of numbers <= n
2. Get minimum cost for all substrings with len >= 2
3. Dynamic programming with memoization for all possible k-splits of the given string.
2
19
Today's Leetcode:
Keys:
1. The problem statement itself is basically the algorithm in plain english
9
366
Today's Leetcode:
Keys:
1. Prefix sums
2. Even and odd prefix sums
3. Even - odd == odd, odd - even == odd
4. Consider the empty prefix, 0.
5. Modulo on your result
Today's Leetcode:
Keys:
1. Prefix sum
2. initialize ans with i32::MAX;
3. check every possible window starting at a given index and greedily minimize ans.
4. Return ans
8
408
Today's Leetcode: Prefix Sum + Monotonic Stack + Binary Search
Keys (to my approach):
1. Keep a prefix sum of the array (for querying)
2. Initialize a monotonic stack (for variable prefix max)
3. Iterate from right to left
4. For current i, get pms(i) defined as ...
1
5
316
... the prefix max sum of the array starting at i e.g.
pms([3,2,1,4,4,]) = sum([3,3,3,4,4])
5. Binary search using your monotonic stack for the j >= i such that pms([i, j]) <= k ans pms([i, j+1]) > k
6. Add the value of (j - i) + 1 to your result.
Return the final result
1
29
Today's Leetcode:
Keys:
1. Keep a count for strictly increasing
2. Keep count of strictly decreasing
3. Keep maximum of either
4. Iterate
5. Greedily update all 3 variables
6. Return the maximum
Today's Leetcode: Minimum cost
Keys:
1. Get min cost for both type 1 and type 2.
2. Use that min cost until need1 or need 2 becomes 0
3. Get min cost for type 1 alone, or type 2 alone
4. You can use cost_both for the "alone" costs
5. Add all these costs.
6. Beware of overflow.
6
299
Today's Leetcode: Stairs cost
Keys:
1. Iterate through the indices
2. For each i, get the minimum cost to jump to (i+1, i+2, or i+3)
3. Memoization.
4
136
Today's Leetcode: Busy Servers
Keys:
1. Keep all free servers in ordered set.
2. Create min-heap for busy servers
3. Initialize busy array
4. Iterate though tasks
5. At start of iteration, free up completed servers i.e. completion <= arrival[i]
6. If no server available, skip...
1
9
310

























