Top
Best
New

Posted by mpweiher 1 day ago

Many hard LeetCode problems are easy constraint problems(buttondown.com)
588 points | 482 commentspage 6
non_aligned 1 day ago|
I think LeetCode tests two things. First, your willingness to grind to pass an exam, which is actually a good proxy for some qualities you need to thrive in a corporate environment: work is often grungy and you need to push through without getting distracted or discouraged.

Second, it's a covert test for culture fit. Are you young (and thus still OK with grinding for tests)? Are you following industry trends? Are you in tune with the Silicon Valley culture? For the most part, a terrible thing to test, but also something that a lot of "young and dynamic" companies want to select for without saying so publicly. An AI startup doesn't want people who have family life and want to take 6 weeks off in the summer. You can't put that in a job req, but you can come up with a test regime that drives such people away.

It has very little to do with testing the skills you need for the job, because quite frankly, probably fewer than 1% of the SWE workforce is solving theoretical CS problems for a living. Even if that's you, that task is more about knowing where to look for answers or what experiments to try, rather than being able to rattle off some obscure algorithm.

Gunax 1 day ago||
Internally, do contraint solvers just do brute force?

It's interesting how powerful contraint solvers are (Ive never used one).

But actually all of these problems are fairly simple if we allow brute force solutions. They just become stacked loops.

cerved 21 hours ago|
No. They use sophisticated algorithms called propagators to prune the invalid solutions from the domains of possible solutions in conjunction with a search strategy, like branch and bound
cratermoon 1 day ago||
I've always maintained that solving LeetCode is more about finding the hidden "trick" that makes the solution, if not easy, one that is already "solved" in the general sense. Look at the problem long enough and realize "oh that's a sliding window problem" or somesuch known solution, and do that.
bradlys 1 day ago||
Everyone misunderstands what LC focuses on. It focuses on - did you grind like everyone else that did to get into this company/region/tech? It allows for people who didn't go to the most specific schools (e.g. Cal, Stanford, etc.) to still get into silicon valley companies if they show they are willing to fit the mold. It's about showing you are a conformist and are willing to work very hard to do something that you won't realistically use much in your day to day job.

It's about signaling. That's all it is. At least it's not finance where it's all dictated by if you were born into the right family that got you into the elite boarding schools for high school, etc. I would've never made it into finance unless I did a math phd and became a quant.

the_af 1 day ago||
> The "smart" answer is to use a dynamic programming algorithm, which I didn't know how to do. So I failed the interview.

Really? This kind of interview needs to go away.

However, coding interviews are useful. It's just that "knowing the trick" shouldn't be the point. The point is whether the candidate knows how to code (without AI), can explain themselves and walk through the problem, explain their thought processes, etc. If they do a good enough reasoning job but fail to solve the problem (they run out of time, or they go on an interesting tangent that ultimately proves fruitless) it's still a "passed the test" situation for me.

Failure would mean: "cannot code anything at all, not even a suboptimal solution. Cannot reason about the problem at all. Cannot describe a single pitfall. When told about a pitfall, doesn't understand it nor its implications. Cannot communicate their thoughts."

An interview shouldn't be an university exam.

x187463 1 day ago||
I agree with this approach. With the exception of testing for specific domain knowledge relevant to the work role, the coding interview should just be about testing the applicant's problem-solving skills and grasp of their language of choice. I would even prefer a take-home style problem that we can review in-person over some high-pressure puzzle. The leetcode interview doesn't seem to correspond to anything a developer actually does day to day.
SJC_Hacker 18 hours ago||
The bar is so high nowadays that simply being able to talk intelligentyly about the problem, ask clarifying questions, getting an inefficient solution and coding it up well does not pass muster.

Even getting an efficient algorithm basically right, is no guarantee.

In some cases there might be alternative solutions which have some tradeoffs, and you might have to come up with those, as well

Miss a counterexample? Even if you get it after a single hint?. Fuck you, you're out. I can find someone who doesn't need the hint

the_af 17 hours ago||
It might be true in the general case, I haven't interviewed for a job for some years, so I may be out of touch.

All I can say is that I do conduct interviews, and that I follow the above philosophy (at least for my round).

scotty79 21 hours ago||
All problems cited are about testing if you can write if's, loops and recursion (or a stack/queue).

They aren't testing if you can write a solver. They are testing if you can use bricks that solvers are built out of because other software when it gets interesting is built out of the same stuff.

CamperBob2 1 day ago||
I implemented the simple greedy algorithm and immediately fell into the trap of the question: the greedy algorithm only works for "well-behaved" denominations. If the coin values were [10, 9, 1], then making 37 cents would take 10 coins in the greedy algorithm but only 4 coins optimally (10+9+9+9).

That's a bad algorithm, then, not a greedy algorithm. Wouldn't a properly-implemented greedy algorithm use as many coins as possible of a given large denomination before dropping back to the next-lower denomination?

If a candidate's only options are to either use a constraint solver or to implement a naïver-than-usual greedy algorithm, well, sorry, but that's a no-hire.

Peritract 1 day ago||
The algorithm they're using must be "Until you hit the limit, take the highest denomination coin that fits beneath the limit. If you can't hit the limit, fall back one step."

That fits your definition of "use as many coins as possible of a given large denomination before dropping back to the next-lower denomination" but will find 10-10-10-1-1-1-1-1-1-1 and stop before it even tries 10-9-anything.

smegma2 1 day ago|||
There is no greedy solution to the problem. A greedy algorithm would start by taking 3 10-cent coins to make 37 which is wrong.
Jtsummers 1 day ago|||
> Wouldn't a properly-implemented greedy algorithm use as many coins as possible of a given large denomination before dropping back to the next-lower denomination?

Yes, and it won't work on the problem described. The greedy algorithm only works on certain sets of coins (US coin denominations are one of those sets), and fails in at least some cases with other coin sets (as illustrated in the bit you quoted).

CamperBob2 23 hours ago|||
D'oh, that makes sense, I didn't consider the case where it would keep returning 10.
the_af 21 hours ago||
By the way, ChatGPT was able to solve this problem and give the correct solution.
Jtsummers 21 hours ago|||
It's in numerous algorithms textbooks and probably a lot of code repositories, so that's not surprising.
the_af 1 hour ago||
I didn't mean it was surprising. I meant literally what I said: I tried it, and it worked. Nothing more, nothing less.
the_af 1 hour ago|||
Interesting that an informative comment, without any implications or insinuations, got downvoted.

HN sucks sometimes. "Intellectual discourse" and "hacker curiosity" my ass.

garrettgarcia 1 day ago||
"Follow-up question since you solved that so quickly: implement a constraint solver."
gnatman 15 hours ago||
“Many hard problems are, to me, quite easy”
techlatest_net 1 day ago|
[dead]