- 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.
- The end of 2019 week 17 was at 5pm. Throughout the season I put in handlers to disable picking, show passive data, etc in the offseason. I never tested it.
- There are a few small bugs. I'll hit them tomorrow. Created the ticket. https://gitlab.com/bmahlstedt-group/supercontest/issues/141.
Wednesday, January 1, 2020
- Remember float('inf') in python.
- Haven't checked zyme in a while, but up to ~45.50.
- https://leetcode.com/problems/merge-two-sorted-lists.
- It's often more convenient to make the recursive call within the function, not in the return clause. Often you want to manipulate the data, or append to the list, or do something before returning the specifics.
- https://leetcode.com/problems/merge-k-sorted-lists. first_iter = True useful in recursion also.
- https://leetcode.com/problems/generate-parentheses. Create all exponential (2^n) permutations, then run verification on them.
- https://leetcode.com/problems/swap-nodes-in-pairs/. Reversing pointer pairs in a linked list. Can't modify values.
- https://leetcode.com/problems/reverse-nodes-in-k-group/. Same, but with general k instead of k=2, alternating every pair.
- https://leetcode.com/problems/remove-duplicates-from-sorted-array/. In-place deduplication in a sorted (thankfully) array. Can't create secondary array, must be constant space complexity.
Subscribe to:
Posts (Atom)