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

SWE, #rust, Competitive Programmer. I am simply the best. ✨Github: https://teapawt.org/t.co/5KKcJ34VEv ✨Codeforces: https://teapawt.org/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,587
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
13
241
... 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
15
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
200
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
423
... 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
33
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
468
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
1
26
620
... 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
29
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
259
... 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
469
I'll drop an explanation tonight
24
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
1
13
300
Today's Leetcode: Keys: 1. Iterate only odd indices 2. Count how many indices i such that s[i] != s[i-1]
8
307
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.
3
24
Today's Leetcode: Keys: 1. The problem statement itself is basically the algorithm in plain english
10
374
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
1
6
204
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
409
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
My solution seems to be sub-optimal. I will be sure to check out the optimal solution
21