-
- Promise. Async object that will return a value in the future.
- If you call an async function, the promise is returned immediately (synchronously) but in a pending state. Later it will become fulfilled or rejected and do something else.
- Can attach a callback to handle the return.
- .then() returns a promise.
- Functional vs OOP.
- Functional uses (wait for it) functions – pure, no shared state, no global mutation. It’s based around actions, and is better if you expect your project to scale by adding actions.
- Object oriented is usually based classes that interact. They share. It’s based around things, and is better if you expect your project to scale by adding things.
- Function composition. Could be decorators (chained functions) or simply meshing the results of multiple returns today. Straightforward.
- Class inheritance vs prototype inheritance.
- The class is a template, not an object. Gives you a template for your subclass.
- The prototype is an actual object. You create clones or slightly different children of it.
- General composition vs inheritance.
- Does B want ALL features of A? Inherit. Only want some? Compose.
- I generally agree with this: https://medium.com/inc./amazon-uses-a-secret-process-for-launching-new-ideas-and-it-will-transform-the-way-you-work-aec5c9121ae.
- Work backward from the customer, not forward from the product.
- Start with the problem and find the solution, don’t create something and then check what it helps.
- Couldn’t find a decent ebook download, so I ordered a hardcover for the first time in years. The man who solved the market, jim simons, rentech. Excited to read, but will probably wait until after interviews.
- NFC wild card games. Vikings and Seahawks advance.
- Divisional games: Ravens/Titans, Chiefs/Texans, Niners/Vikings, Packers/Seahawks.
- The overtime rules are so dumb. The percentage of a goalie blocking a pk in a shootout is about 30%. That’s about the same ballpark as the probability of getting a touchdown on a drive. Imagine if the soccer game ended when the goalie blocked the first kick.
- Made 12 new powders.
- Caught up with Spencer. Slater’s on the pier. Miss him! Bomb nashville chicken sandwich.
- Talked interviews, personal projects, SpaceX, software, life, investing.
- Rewriting the autotest ui and other frontends in python with transcrypt.
- Buying stock in a company is not directly financially enabling them, the stock pool is mostly set. It’s just changing hands. Buying a vote in investors meetings. It does increase volume and other things that make the company seem more valuable.
- Certification got convoluted. Half is encryption, the other half is identification. They should be separate.
- Practice problems.
- https://www.hackerrank.com/challenges/friend-circle-queries/problem. Wrote a solution in 10min that passed half the tests. You can optimize further with disjoint sets, but I feel comfortable with my non-fancy solution.
- https://www.hackerrank.com/challenges/maximum-xor/problem. Solved the brute force way, O(mn). To get it in linear time instead of quadratic, you have to use something called a Trie, which is basically a binary tree with 0s and 1s. https://en.wikipedia.org/wiki/Trie.
- https://www.hackerrank.com/challenges/insert-a-node-at-a-specific-position-in-a-linked-list/problem. Standard linked list insert into position. I always have to think for a minute about the while loop. Manage your own index, keep track of prev/next, and make a few things conditional on index == 0. You can simplify it if you create an entirely new list, but the in-place version is better for space situations.
- https://www.hackerrank.com/challenges/insert-a-node-into-a-sorted-doubly-linked-list/problem. I wrote the long-winded solution, which worked. HOWEVER. You can do these ll problems with recursion. It’s way more concise, it’s just a bit harder to conceptualize imo.
- https://www.hackerrank.com/challenges/reverse-a-doubly-linked-list/problem. Same thing. Try to thing about the recursive solution. If it’s too complicated, fall back to iterative.
- https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists/problem. Looped through both. Quadratic solution, which passed all tests, but there is an O(n) algorithm on the discussion page. It’s just less intuitive.
- https://www.hackerrank.com/challenges/ctci-linked-list-cycle/problem. Check if there’s a cycle in a linked list. Easy. The key here is knowing that you can store objects as keys in a hash table. Then simply loop through the ll and bookkeep them. If you ever already have one, there’s a cycle. The hash lookup is constant time.
- https://www.hackerrank.com/challenges/binary-search-tree-lowest-common-ancestor/problem. Tree problems make me think for a bit longer. Remember it’s like a linked list, but you each node has two pointers instead of one. This yields two calls in recursion, or two expansions in iteration. This particular one could be solved with math, because you’re given a binary search tree that’s already balanced, but you could walk it all the same to find the answer.
- https://www.hackerrank.com/challenges/ctci-is-binary-search-tree/problem. Walk through a BST. I solved it both iteratively and recursively. An additional note: a binary search tree is valid if the inorder traversal is sorted properly.
- https://www.hackerrank.com/challenges/tree-huffman-decoding/problem. Very easy question. Solved it quickly, but the wording was overly complicated.
- https://www.hackerrank.com/challenges/balanced-forest/problem. Didn’t try. This problem is too long.
- https://www.hackerrank.com/challenges/torque-and-development/problem. Build an adjacency dict of {node: {neighboring nodes}}. Then traverse it and group them.
- https://www.hackerrank.com/challenges/find-the-nearest-clone/problem. For BFS, literally just pop from the from of the queue instead of the end of the stack. The graph problems have been longwinded for me.
- https://www.hackerrank.com/challenges/ctci-fibonacci-numbers/problem. Recursive fibonacci. Easy as pie. Remember it’s 2^n (exponential) without dp, and down to O(n) with memoization.
- https://www.hackerrank.com/challenges/ctci-recursive-staircase/problem. The staircase problem with 1/2/3 hops. This is the same as fibonacci with 3 numbers in the sequences, and the 3 exit conditions in order are 1/2/4. Remember these get much faster with a cache. Check if n is in the cache, and only recurse if it’s not.
- https://www.hackerrank.com/challenges/recursive-digit-sum/problem. Easy. Recurse.
- https://www.hackerrank.com/challenges/crossword-puzzle/problem. Thought about it for about 20min, but then didn’t take the time to solve. A very straightforward problem, but tedious. This is like a simpler version of the 5squared puzzle I’ve solved (programmatically).
- https://www.hackerrank.com/challenges/balanced-brackets/problem. Easy. Just run a stack for open/close. Few small corner cases.
- https://www.hackerrank.com/challenges/ctci-queue-using-two-stacks/problem. Lol what a silly question. Just implement the methods of a queue using a python list, enqueue/dequeue/peek.
- https://www.hackerrank.com/challenges/largest-rectangle/problem. Same as the leetcode one. Use two pointers coming in from both sides.
- 11 left. Will do tomorrow.
- XOR of two integers is just the XOR of the bit representations of the integers. In python ^ is the operator for XOR. For example, 2 ^ 1 = 3.
- In python it’s set.add vs list.append.
- In python sets are implemented with hash tables, so lookup is basically the same as a dict (extremely fast).