
SWE, #rust, Competitive Programmer. I am simply the best. β¨Github: https://xitter.gq/t.co/5KKcJ34VEv β¨Codeforces: https://xitter.gq/t.co/uYYkeQXauq
Online
Joined September 2019
- Tweets1.4K
- Following484
- Followers287
- 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,590
Today's Leetcode: Friend requests.
I have solved a harder variant of this problem on codeforces:
codeforces.com/contest/2285/β¦
Peep my runtime in img 3
Keys:
1. Initialize a DSU
2. Store for each i, all it's restricted person's j in a set
3. On a request to join i and j, get the...
1
10
408
... parents of both (i, j) = (p, q)
4. Check if (p, q) is a restricted pair.
5. If they are, you can return early.
6. Let degree[p] = the sum of restricted persons of each dsu member parented by p
7. Use the lower degree, and scan through to ensure that no restricted persons...
1
3
22
Today's Leetcode: Cost optimization 2
Keys:
1. In this case, you can only ever add 1 copy (paid) or 2 copies (1 free + 1 paid)
2. We can quickly get all the multiples of a number using sieve of Eratosthenes.
3. This gives us the number of times we can buy two copies for...
1
11
314
... a given price p
4. The price, p, must not be more than 2 times the minimum price in the array.
5. Instead of buying 2 copies one at a time, batch buy on each instance and if you cannot batch buy as much as possible with the current price.
6. If the remaining budget cannot ...
1
1
22
Today's Leetcode: Cost optimization
Keys:
1. Find the most items you can get by buying one of some items (DP)
2. Use the remaining budget to repeatedly buy the cheapest item
13
120
Today's Leetcode: Stone Piles
Keys:
1. Try i removals from 10, down to 1.
2. If i stones cannot be removed, the result depends on the parity of i (true for odd i, false for even i)
3. if all i can be removed, Alice cannot make a move, return false
9
253
Today;s Leetcode: Product Array
Key:
1. Brute force
2. Set a limit on the max allowable product, e.g. Pi(x) for x in [1, 10].
Today's Leetcode: Beware of 0 (I previously solved on Valentine's day last year)
Keys:
1. Generate a prefix product array (PPA) with the numbers
2. The product of last k elements is just the nth product/(n-k)th product where n is length of prefix product array.
3. Notice that...
... with a PPA, all elements after zero are also zero, so if the previous element is 0, we keep the current element alone.
4. Let z be the position of the most recent 0.
5. if the (n-k)-th element comes before z, then we return zero, else see #2
38
Today's leetcode: string search
Keys:
1. Find the first occurence of 'b': f(b)
2. Find the last occurence of 'a': l(a)
3. return l(a) < f(b)
Simpler Alternative:
Check if the string contains "ba"
Today's Leetcode: trees
Keys:
1. Build the adjacency list
2. Depth-first search
3. Keep track of most recent ancestor with given value as you traverse.
4. Get the node's new parent as you traverse
5. let s(x) be subtree size of x, s(x) = 1 + sum(s(y)) for all y which ...
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
267



























