Aizon the DreadedHippy πŸ¦€ (@HippyDreaded) header
Aizon the DreadedHippy πŸ¦€ (@HippyDreaded) profile picture

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
Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)Photo by Aizon the DreadedHippy πŸ¦€ (@HippyDreaded)
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
... from the members of p is a member of q. 8. Return the outcome of these checks 9. If joinable, combine the degrees and groups of p and q, also join p and q in the DSU and set ans[i] to true 10. Otherwise sent ans[i] to false
4
17
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
... batch buy everything, the iteration should end 7. Add (remaining budget /min price) to the final answer 8. Carefully select your choice of Data Structures
1
15
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: Binary Search + Rolling Hash + Frequency 1. For a subarray with one occurrence, extending it keeps its single occurrence. 2. Truncating it however may produce multiple occurrences 3. Based on #1 & #2, the function is monotonic. Thus, Binary search 4. We can...
1
1
16
287
... can check if a given subarray length is valid by counting all subarrays of a given length and counting the frequency. 5. If we see a frequency of 1, it's valid, otherwise it isn't 6. Speed up the check by using a rolling hash algorithm e.g. Rabin-Karp
1
18
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].
1
13
205
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...
1
3
13
437
... 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"
1
19
471
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 ...
1
2
26
640
... which is a child of x. 6. Every node initially has a subtree size of 1. 7. Since you update the node's parent during traversal, you can contribute its own subtree size to its updated parent before you exit the node. 8. Return the subtreesize result
1
31
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
... by setting dp[i] = dp[i+1] and subtracting 1 from both cases i.e, dp[i] = [dp[i+1][0] - 1, dp[i+1][1] -1) 8. answer is (max(dp[i][0], dp[i][1]) - i) + 1 Note: Since i depends only on i+1, you can use variables instead of an array.
1
23
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
475
I'll drop an explanation tonight
25