-
- 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).
-
- Practice problems.
- https://www.hackerrank.com/challenges/ctci-bubble-sort/problem. Just implement a bubble sort. One loop through n-1, check if bigger than next, swap if so. Then simply wrap the whole thing in a blind loop to run n times, which guarantees it’ll be sorted when finished.
- https://www.hackerrank.com/challenges/mark-and-toys/problem. Basic sort.
- https://www.hackerrank.com/challenges/ctci-comparator-sorting/problem. Write a comparator method of a class. Pass two objects, do whatever logic, then return -1 if obj1 goes before obj2 or 1 if opposite. Then you can pass the Class.comparator function as a key to a sort call, or whatever.
- https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem. Tougher, but I really enjoyed this one. Success rate was low, in the 30s. Sliding window for median, remember you can access it by index (middle if n odd, (middle + middle-1) if n even). To remove/insert in the sliding window, use the bisect module for speed.
- https://www.hackerrank.com/challenges/ctci-merge-sort/problem. Brainstormed this one for about 30m and then chose not to implement. The question is basically “write you own merge sort”. O(nlogn). This allows you to count the inversions. No thanks.
- https://www.hackerrank.com/challenges/ctci-making-anagrams/problem. Simple. My solution was cool.
- https://www.hackerrank.com/challenges/alternating-characters/problem. The easy ones are easy.
- https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem. Little more complicated, but in syntax. Nothing algorithmically special here.
- https://www.hackerrank.com/challenges/special-palindrome-again/problem. Tired of palindromes. I don’t like these problems.
- https://www.hackerrank.com/challenges/common-child/problem. Didn’t care to do this one either. Don’t like longest common subsequence problems. Remember the table of 1s and 0s, slowly sum as you move down and right.
- https://www.hackerrank.com/challenges/minimum-absolute-difference-in-an-array/problem. Nice change of pace. GREEDY algorithms. If you find yourself facing a quadratic solution, just sort! See if that helps.
- https://www.hackerrank.com/challenges/luck-balance/problem. Simple.
- https://www.hackerrank.com/challenges/greedy-florist/problem. Solved, but dumb question. It’s worded very ambiguously, and I had to modify the footer because the main function was completely missing a required argument (first time I’ve seen this on hackerrank).
- https://www.hackerrank.com/challenges/angry-children/problem. Easy. Fast. Don’t forget outside of this section; consider a sort!
- https://www.hackerrank.com/challenges/reverse-shuffle-merge/problem. Not gonna touch this one. Not worth my time, since it’s limited. Trying to understand the problem description alone took 10 minutes.
- https://www.hackerrank.com/challenges/ctci-ice-cream-parlor/problem. Find a pair within 1d array, so iterate through it once, build a complement map.
- https://www.hackerrank.com/challenges/swap-nodes-algo/problem. Didn’t do. This question takes 30 minutes to read.
- https://www.hackerrank.com/challenges/triple-sum/problem. One you have to think about, doesn’t fit a standard pattern. Solve an easy case and you’ll see you’re best off approaching along a specific dimension (q).
- https://www.hackerrank.com/challenges/minimum-time-required/problem. An interesting one as well. Basically implement your own binary search. Find best and worst case for lower and upper bounds, bisect them, calc the result, then shift one bound depending upon what the produced value is. Put this all in a loop `while lower_bound < upper_bound`.
- https://www.hackerrank.com/challenges/maximum-subarray-sum/problem. <30% solve rate. Took a stab at it. Started with ~30m of whiteboarding. Reached the conclusion that the module of the sum is the modulo of (the sum of the modulos of the individuals). This is the key piece.
- https://www.hackerrank.com/challenges/making-candies/problem. Not really a search problem, just walk through the simulation. My solution was the right complexity (passed 35/49 tests), just needed smaller optimizations here and there.
- https://www.hackerrank.com/challenges/flipping-bits/problem. “Flipping bits” is just subtracting from the max size. So if you flip bits on a 32bit unsigned integer x, the result is 2^32-1-x.
- https://www.hackerrank.com/challenges/ctci-big-o/problem. Check if a number is prime. To do so, iterate only over odd numbers (because even divides by 2), and only up to square root of x. Every pair of factors, if it exists, has one number below the sqrt and one above, so you only need to check up to the integer at floor(sqrt(x)).
- Only 30 problems left. The average difficulty is a little on the easier side, too. The hardest is like 40% pass rate. I’ll try to do most tomorrow so that I can focus on the open-ended questions monday. Behavioral, design, etc.
- To switch two items in an array in python in one operation, just do:
- list[index1], list[index2] = list[index2], list[index1]
- Instead of doing quotient = math.floor(num/den) and rem = num % den, get both with quotient, rem = divmod(num, den).
- Oh shit. You can also get the quotient directly with // in py3. 11 // 2 results in 5. Don’t need math.floor everywhere.
- If n is given for a problem to be 10^9, you probably need a linear solution. If 10^5, try to find an nlogn algorithm. If 10^4, quadratic is ok.
- Red-black trees are colored to preserve balance.
- Push, meditate.
- Ordered more preferred stock.
- AFC playoffs. Texans and Titans moving on.
- Supercontest. Disabled the emailer during the offseason.
- The machine was out of disk space, so I sshed in and ran docker system prune -af to free up 17.89GB. Remember to create the network and restart the nginx-proxy containers as well after this operation.
-
- Took the BMW online test. 8 questions. Each was a 1-3m video recording of my answer.
- All had unlimited time to think – I was kinda hoping they’d be restricted in time and in #takes (could shine more I guess).
- The whole test was java heavy.
- JDK/JRE/JVM. Generics.
- Creational design patterns. Prototype, factory, singleton.
- JEE APIs. JavaMail – like flask-mail. Persistence – like sqlalchemy. Security API – like flask-user and flask-admin.
- Join differences.
- I know these, just typing out for refresher:
- Inner. Normal, condition matches in both tables.
- Left. Return the full left table with matching records from the right, and null otherwise.
- Right. Return the full right table with matching records from the left, and null otherwise.
- Full. Return both left and right (basically stitch both tables together and fill null with nothing).
- Good summary: http://www.sql-join.com/sql-join-types.
- Flash will not be supported on chrome at the end of 2020. I’m still amazed Amazon’s conference room requires it.
- Apple TV+, Disney+, Hulu, Showtime, HBO, Netflix, Peacock (NBC) coming soon.
- Smoked a pork shoulder. Handpressed tacos with maseca.
- Cooked a couple pounds of garbanzo beans.
- Turns out that the IR lamp in the terrarium isn’t dead, I simply had the outlet disabled.
- Supercontest.
- Had to decide to implement an offseason explicitly or simply extend week 17 to last through the remainder of the year. The latter is much easier, so I did that. The former bleeds into g.current_week, current_season, and downstream into is_paid_user, leagues, and much more. It’s more proper, but much more complicated and unnecessary at this point. If I need an offseason-specific view in the future, I can add this.
- Fixed and deployed.
- Practice problems.
- Whiteboard most of these. Transferred to computer to check syntax.
- Another thing above leetcode that’s superior to hackerrank: it reports time and mem usage, as well as your percentile.
- https://www.hackerrank.com/challenges/counting-valleys/problem.
- https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem.
- https://www.hackerrank.com/challenges/repeated-string/problem.
- https://www.hackerrank.com/challenges/2d-array/problem.
- https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem.
- https://www.hackerrank.com/challenges/new-year-chaos/problem. This was started to get a little tougher. Write down a few simple cases, reason through the logic.
- https://www.hackerrank.com/challenges/minimum-swaps-2/problem. This one is dumb. Hacker rank has some pretty misleading/bad questions.
- https://www.hackerrank.com/challenges/crush/problem.
- Sometimes a problem has two dimensions that you can iterate over, say N and M, and it’s worth putting an IF statement in your whole algorithm to dictate which you do.
- https://www.hackerrank.com/challenges/ctci-ransom-note/problem. Remember hash tables are faster lookup than arrays. If you’re going to access more than once later, it’s usually worth iterating over the array a single time creating a dict with word counts, and then accessing that later, rather than finding the word in the original array.
- https://www.hackerrank.com/challenges/two-strings/problem. Hash for lookup speed!
- https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem. Dumb questions. Worded with zero clarity. Accepts a brute force O(n!) solution, but indicates nothing of such constraints.
- https://www.hackerrank.com/challenges/count-triplets-1/problem. Remember remember. For COUNTING problems, your gut should tell you to use a hashtable for fast lookup. I got a general solution that passed most the tests, but the final answer that passes all is VERY elegant. Was cool to read.
- https://www.hackerrank.com/challenges/frequency-queries/problem. Crushed it. Defaultdicts, tested with int, list, and dict. Kinda cool to have a defaultdict whose default is a nested dict.
- Went through the 4 basic “approach” videos as well: https://www.hackerrank.com/interview/interview-preparation-kit/tips-and-guidelines/videos.
- A factorial multiplies each integer’s product, but in some cases for combinations you need to add them, like the sum of all integers from n to 1. This is called the binomial coefficient, and it’s n(n+1)/2. It always yields an integer. This comes up in regular life way more often than you might think; pay attention for it.
- In python, collections.defaultdict(int) will make the default zero. Similarly, (list) will make the default an empty list. This is very useful to avoid the annoying “check if key exists, append if so, create if not” clauses.
- defaultdict is a little faster than Counter, as well.
-
- Double Irish, Dutch Sandwich = some big companies avoid taxes by shifting money overseas to irish/dutch subsidiaries. Google has done this with over 20 billion annually since 2017, tax free.
- A JIT compiler is close to a regular old interpreter, in that both execute at runtime. The one difference is that the compiler will still compile the code all the way down to machine language. An interpreter usually runs the code directly or some middleground (like python’s bytecode pyc).
- Python has one called Numba, which tries to compile everything down to c. This gives you nice warnings for situations where you might be doing something python-specific (like a dynamic array with ints and strings) which can’t compile.
- Numba also gives you the ability to write python code which executes almost as fast as c. Very useful for compute-intense tasks.
- Current portfolio shot up to an easy 52wk high. My return so far: 23.5% in 6wks. S&P500 rose ~3.5% in the same time frame. +20 alpha, even in this weirdly bullish time.
- Fresh order.
- Backed the puzzle.
- Turned the soil in the terrarium to keep fresh, need to replace after move.
- Watched Winchester. Shiv from succession is in it.
- In order to enter the amazon chatroom, I had to install flash player and enable. Huge no-no.
- Add the canonical repository. Apt install.
- Within chrome, change to “ask” instead of “block all flash” – annoying.
- Ultimately got in at 12:30, not 12. Will have to join next week.
- Whiteboard arrived. Practiced a few problems handwritten instead of typed.
- Due to all the problems with internal political activism, google has banned politics at work: https://medium.com/enrique-dans/suddenly-at-google-its-get-on-the-program-or-get-out-5ce19930f554.
- Brainstormed open-ended answers to the generic question “how could you speed this up?” Got 12 good ones so far.
- Armin Ronacher’s open-source group is call pocoo. Sphinx, flask/werkzeug/jinja, click.
- Remember jupyter is convenient for early development. Say you’re writing a script/module for the first time. The notebook gives you the editor/ide to build the script AND the terminal to run the script all in one. Check outputs, inspect vars, etc. Bonus: you can add text/plots/documentation as well.
- Started the garbanzo bean soak for tomorrow. Probably won’t make hummus, just keep as a side for the smoked meat.
- Made sushi. Rice, seaweed, tuna, hot sauce. Slowly clearing out the random kitchen items for the move.
- Cleaned the kitchen, getting rid of ~8 old pots/pans/lids.
- BMW set up an interview.
- Sparkhire is an online video interview platform.
- Submitted. Was allowed to record responses to questions. Time-limited.
- Bought sirloin steak and a pork butt. Brined.
- Vons has way worse meat than costco. Twice the price, half the quality.
- The pork shoulder was bloody (had been frozen) and didn’t smell nearly fresh.
- Cleaned and reseasoned the old cast iron pan.
- Steamed crab, panfried sirloin, baked potato, asparagus.
- Redeemed Eric’s christmas lotto tickets. Paid $5 total, won $15 total.
- Pull.
- Settled up the big bear trip in splitwise, $320.
- Bootstrap headings, bold and opinionated: display-1 through display-4.
- Supercontest.
- Handled the offseason ticket.
- Investigated. Found 7 issues.
- The standard disweb dashflo shard for widgetbot is broken again. I’m not going to touch it again until next year, and hope they stabilize their DOS issues by then.
- Fixed 2 of the 7 issues, will finish the rest tomorrow.
-
- 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.
-
-
- Hash tables high space fast speed.
- S&P has almost quintupled since the low of the 08-09 crisis.
- I know the # in a URL, but its formal name is anchor or fragment identifier, the subsection to focus to.
- Escape room up in Big Bear.
- Among the bay friends, final percentages and rankings were:
- frank 58.8
- nick 58.8
- david 57.1
- quique 56.0
- art 55.9
- diego 55.7
- brian 51.2
- omar 47.5
- Approximate payouts:
- 1st $730
- 2nd $325
- 3rd $180
- 4th $140
- 5th $115
- 6th $90
- 7th $80
- 8th $70
- 9th $60
- 10th $50
- 1st place comparison:
- Westgate Supercontest: 59 pts, 58-2-25, 69.4%.
- South Bay Supercontest: 53 pts, 52-2-31, 62.4%
- Would have tied for 25th in the full contest.
- The 9 people who tied for 26th last year each got a payout of $14,844.65.
- Brainstormed a few more return questions.
- Practice problems: