Parity Bits

Three Comments on Leetcode

My return to Leetcode

I was recently introduced to wordle (and variants) by some colleagues, and it's pretty fun and slick. I've always been delighted with its user-respecting daily problem cadence. Very happy to see it succeed and I hope the model remains popular.

But after a couple of weeks of off-and-on, I'm finding the mechanics of the game don't mesh well with me personally.

I spent years working with young and not-so-young kids doing reading remediation work, which led me to develop a fairly systematic and internalized catalog of English phonics. I also spent years twiddling with an entirely custom keyboard map in order to combat RSI, so I've also got a pretty good internal handle on English letter frequency distributions, including 2 and 3 letter combinations. (Thanks to Peter Norvig)

Add a background in CS and math to the above, and my approach to wordle puzzles has converged on something extremely mechanical and not that much fun.

OK. Wordle is great, but maybe not great for me.

Still, I enjoyed the daily cadence, and was interested to pick up something in its place. So: why not Leetcode? I've given it a go, and am enjoying it so far. I know that Leetcoding as a cultural norm is divisive, but I've always intrinsically enjoyed this class of puzzles.

Preamble preamble preamble. Here are my comments.

Global Scope is Persistent

This comment pertains at least to JS / TS. Could be more!

In the context of a these one file toy functions, where every other question seems to be a dynamic programming doodad, my recurring impulse is to park a memo global outside of the function.

const memo = {};

function findTheMostFooBar(arr: number[], someParam: number) {
    // loop or recursion that writes to memo whenever
    // the Fooness of a Bar is calculated, and checks
    // memo whenever we want to know the Fooness of a bar.

But this keeps breaking, because things written to memo in test case 1 are still there during test case 2, and so on. It's not super hard, retrospectively, to guess why this would be the case: the test runner must do something like

But what about the context where you're thinking hard about some tricky thing, and it breaks in weird ways, and you inspect the consol.logged contents of your failing test cases and they make no sense at all, and you're generally doubting your sanity? In that context, the relevant context, it's not as easy to guess that information from individual test cases are leaking into one another.

In real life, there are containered envitronment type things where the setup / teardown gives you a predictable starting state for each test case, and I guess I continually make the incorrect assumption that the same happens here.

Should it though?

Pick Random

Listen here you rascals. When I have a big list of problems displayed, and I press a button that says 🔀 Pick One, I don't want it to pick a members-only problem that I have to back out of.

I completely respect your need to hound me for money. But I think a better method here is an occasional pop-up with something like "Looks like you're enjoying things. We've got extras!", a few links, and a click-through.

Each time I back out of the members-only problems, I have to wait a while for the page to settle down after its first render. The 🔀 Pick One button does a vertical jump for me, and if I try to click it before the jump I end up missing. A tiny humiliation every time.

(This last part could also be improved if 🔀 Pick One were an actual anchor link which I could select by keyboard...)


Has leetcode Hard become harder over the past few years? Around 30 months ago I was looking to transition back into the software industry after a six or seven year gap. I went through a period of Leetcode grind, and managed to bludgeon out solutions to about a dozen of the hardest-of-hard problems at the time according to acceptance rate.

This time around, I've really struggled with the randomly picked Hard questions, to the point where I've more or less decided to back off from them for a while.

Four plausible explanations which could all be true at once: