-
- Interesting. Would have expected more:
- Pure function = doesn’t affect any global state, a call can be swapped out for its result without effect.
- Home from big bear nye/beans. 2020.
- Practice problems:
- https://leetcode.com/problems/remove-element/submissions/. Another delete-in-place, constant memory problem. While loop, use your own index, del that val or increment. This allows in-place, because you’re not iterating over the array while you modify it; you’re iterating under your own volition and then simply accessing the array by index as needed.
- https://leetcode.com/problems/implement-strstr. Find index of substr. Not as simple as keep a running total, you have to do it for (possibly) n times, because a new instance of the match might begin WITHIN another search. Think mississippi, looking for issip – can’t fail after the first one because the actual answer starts DURING it. Instead of iterating over the haystack char by char, check the whole needle with each matching first char.
- https://leetcode.com/problems/divide-two-integers/. This one was a nice change. Write a divide function without using mult, abs, etc. You basically have to loop and treat all multiplications as additions, then use comparators for less/greater than. It’s constant in time and space, at whatever number the max size the integers can be (2^32).
- https://leetcode.com/problems/substring-with-concatenation-of-all-words. Sliding windows. Reduce the problem from words to chars, then simply find permutations.
- https://www.hackerrank.com/challenges/sock-merchant/problem.
- I like hackerrank’s organization of different problems into groups (these are recursion, dp, dicts, sorting, searching, etc). But it’s still terrible in that function input/output is by FILE. It clutters up your solution space.
- Man I love data:
- (bool func 1) != (bool func 2) is XOR in python. Makes clean one-liners.
- Checked supercontest.
-