Top
Best
New

Posted by mpweiher 9/12/2025

Many hard LeetCode problems are easy constraint problems(buttondown.com)
679 points | 533 commentspage 3
deepsun 9/13/2025|
As an interviewer, I gave one pretty simple task (people solved it in as little as 8 minutes), wasn't using any real CS, even though I'm good at it.

The reason was that aboint 70% of candidates couldn't write a simple loop -- to filter those out. The actual solution didn't matter much, I gave a binary decision. The actual conversation matters more.

Tade0 9/13/2025|
This. Main point of giving candidates CS problems was always to weed out those who couldn't program at all, but somehow were still in the industry. I worked with such people - it's unpleasant.

Somehow someone figured that giving harder problems should result in better candidates. Personally, despite having passed most of the tests I've been subjected to, I don't see the connection.

dataflow 9/12/2025||
My beef with someone using a constraint solver here is that they almost certainly wouldn't be able to guarantee anything about their solution other than that, if it produces an output, it will be correct. They won't be able to guarantee running time, space usage, or (probably for most tools) even a useful progress indicator. The problem isn't merely that they used another tool - the problem is that they abstracted away critical details. Had they provided a handwritten solution from scratch with the same characteristics, it would've exhibited the same problems.

This doesn't mean they can't provide a constraint solver solution, but if they do, they'd better be prepared to address the obvious follow-ups. If they're prepared to give an efficient solution afterward in the time left, then more power to them.

Der_Einzige 9/12/2025|
[flagged]
dataflow 9/12/2025|||
> First of all, Nice ChatGPT response

What the heck are you talking about? I didn't even visit ChatGPT today.

CamperBob2 9/12/2025|||
That's an en-dash, not an em-dash
Der_Einzige 9/12/2025||
"It's not X, It's Y"
graynk 9/12/2025||
I don't think someone with an account from 2012 and 20k karma would be posting LLM-generated comments. It also doesn't read as one. It doesn't even use the "it's not x it's y" formula, it contraposes things against each other. Like I just did.
thomasahle 9/12/2025||
Interview:

> We can solve this with a constraint solver

Ok, using your favorite constraint solver, please write a solution for this.

> [half an hour later]

Ok, now how would you solve it if there was more than 100 data points? E.g. 10^12?

nemetroid 9/12/2025||
Maybe some preprocessing, maybe column generation, depends on the problem.
Avshalom 9/13/2025||
Well how would you solve it if there were 10^12 data points
bradlys 9/12/2025||
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 9/12/2025||
> 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 9/12/2025||
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 9/13/2025||
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 9/13/2025||
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).

Gunax 9/12/2025||
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 9/12/2025|
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
jcul 9/13/2025||
I've never used constraint solvers, seems like black magic. Need to fill that gap in my knowledge.

But how do they work, what is the complexity of the solution, for example for the stock prices, is it O(n^2)?

coarise 9/13/2025|
General constraint satisfaction problem is NP-hard.
gnarlouse 9/12/2025||
Been working on a calendar scheduling app that uses a constraint solver to auto schedule events based on scheduling constraints (time of day preferences and requirements, recurrence rules), and track goal progress (are you slipping on your desired progress velocity? Get a notification). It’s also a meal planner: from a corpus of thousands of good, healthy recipes, schedule a meal plan that reuses ingredients nearing expiration, models your pantry, estimates grocery prices, meets your nutritional goals. Constraint solvers are black magic.
cerved 9/12/2025|
Which solver do you use?
gnarlouse 9/13/2025||
Google ORTools’ CpSolver, with IntervalVars for the calendar portion.
cerved 9/13/2025||
Presumably you run it with multiple workers, preferably in parallel (it's designed to run like that)

Depending on your problem and how you can solve it (single threaded & low memory vs. anything goes) it might be a good idea trying other solvers. OR-Tools CP-SAT(LP) pretty much never does bad on a any problems but there are other CP-SAT solvers like Chuffed & Huub as well as Gecode which is a pure CP solver that does great providing you can make a gif search heuristic up front. Another option is of course racing solvers.

Then there are other things like MIP solvers, CBLS solvers etc. The nice thing with MiniZinc is that it's pretty easy to compare different solver backbends for a problem

gnarlouse 9/14/2025||
Wow thanks, I’ll have to look at those. The CPSAT was an LLM suggestion that I just ran with after doing some very weak research—im not a constraint programming researcher by any means. Since we’re on the topic and you seem knowledgeable, any good primer literature I might check out for understanding the basis of tweaking constraint solvers? I have started running into some performance issues after integrating an optimization function, and have started to wonder how can I claim back some performance.
mzl 9/14/2025|||
The MiniZinc Coursera courses (https://www.minizinc.org/resources/#courses-title) are useful to get a good basis for understanding constraint programming. It’s not a fast solution being full courses, but it is a very good resource.
cerved 9/16/2025|||
The Coursera courses are a great resource for learning how to model problems.

> any good primer literature I might check out for understanding the basis of tweaking constraint solvers? I have started running into some performance issues after integrating an optimization function, and have started to wonder how can I claim back some performance.

There is usually less tweaking of solvers and much more remodeling the problem using a different viewpoint or constraints to solve the problem. There courses teach you that. But beware that's it's not so trivial.

Also, careful with LLMs and constraint solvers, sometimes they yield absolute rubbish.

teleforce 9/15/2025||
Constraint programming complement ML/AI/LLM nicely in system solving real world problems [1],[2],[3],[4]. One of the highest stakes and hardest engineering problems namely wireless spectrum frequency allocation was solved by constraint programming and presented in [1]. Now anyone can try to solve the problem in a MiniZinc tutorial. Fun fact, there's also Knuth in the presentation audience trying to get some info on the subject matter perhaps for his next book.

[1] Logic, Optimization, and Constraint Programming: A Fruitful Collaboration - John Hooker - CMU (2023) [video]:

https://www.youtube.com/live/TknN8fCQvRk

[2] "We Really Don't Know How to Compute!" - Gerald Sussman - MIT (2011) [video]:

https://youtube.com/watch?v=HB5TrK7A4pI

[3] Google OR-Tools:

https://developers.google.com/optimization

[4] MiniZinc:

https://www.minizinc.org/

faangguyindia 9/12/2025|
I avoided all this just by becoming a contractor, i ship solution, no me tests me for leetcode ability
never_inline 9/12/2025||
> faangguyindia

> contractor

Do FAANG hire contractor in India?

monknomo 9/12/2025||
I mean, yeah, they do.
shutupnerd0002 9/12/2025||
[flagged]
gman2093 9/12/2025|||
apex predator of grug is complexity
awalsh128 9/12/2025|||
No me no nice
More comments...