Need help?
<- Back

Comments (475)

  • torginus
    Very interesting article and good points.But how about we flip the original statement around:Many problems thought to require giant software packages/libraries are very solvable locally if you know what you are doingThis is why LC is actually meaningful - imagine if you faced the coin challenge problem IRLin prod and you decided to pull in a constraint solver - what would've been a 25 line function now is a giant python library that carries 30MB of native dependencies around.These solutions are often lacking in many ways, since mentally offloading some of the work means you don't have to understand the problem in depth or how the designated tool solves it, which can lead to nasty surprised in production.We see this everywhere - people pulling in questionable npm packages to save themselves 30 mins of thinking or 20 mins of reading docs - people convinced that you do need that huge 3D framework that comes with an editor to make a WebGL widget on your landing page etc.You are more willing to accept bloat of others, just because they pulled in Electron, because they were too afraid to learn how native UI works.People need to be more curious, and strive to be more knowledgeable.
  • holden_nelson
    I feel like if I'm being asked this in an interview, they're not asking me to use a constraint solver, they're asking me to _write_ a constraint solver. Just for a specific constraint problem, not a more general constraint solver.
  • kccqzy
    Great insight. But this is sadly not applicable to interviews.> It's easy to do in O(n^2) time, or if you are clever, you can do it in O(n). Or you could be not clever at all and just write it as a constraint problemThis nails it. The point of these problems is to test your cleverness. That's it. Presenting a not-clever solution of using constraint solvers shows that you have experience and your breadth of knowledge is great. It doesn't show any cleverness.
  • tracker1
    My biggest problem with leetcode type questions is that you can't ask clarifying questions. My mind just doesn't work like most do, and leetcode to some extent seems to rely on people memorizing leetcode type answers. On a few, there's enough context that I can relate real understanding of the problem to, such as the coin example in the article... for others I've seen there's not enough there for me to "get" the question/assignment.Because of this, I've just started rejecting outright leetcode/ai interview steps... I'll do homework, shared screen, 1:1, etc, but won't do the above. I tend to fail them about half the time. It only feels worse in instances, where I wouldn't even mind the studying on leetcode types sites if they actually had decent explainers for the questions and working answers when going through them. I know this kind of defeats the challenge aspect, but learning is about 10x harder without it.It's not a matter of skill, it's just my ability to take in certain types of problems doesn't work well. Without any chance of additional info/questions it's literally a setup to fail.edit: I'm mostly referring to the use of AI/Automated leetcode type questions as a pre-interview screening. If you haven't seen this type of thing, good for you. I've seen too much of it. I'm fine with relatively hard questions in an actual interview with a real, live person you can talk to and ask clarifying questions.
  • hermannj314
    Most interviews are based on the premise that if a diabetic can't synthesize their own insulin in their basement, they are somehow cheating at the game of life.If my wife's blood sugar is high, she takes insulin. If you need to solve a constraint problem, use a constraint solver.If your company doesn't make and sell constraint solving software, why do you need me to presume that software doesn't exist and invent it from scratch?
  • liqilin1567
    This is a massive thread. For anyone just arriving, here's a quick attempt to distill the main arguments from the 450+ comments.The core of the discussion is a sharp divide on the value of LeetCode-style algorithmic interviews. It seems to boil down to these two main camps:1. The Case Against: The primary critique is that these problems are poor predictors of on-the-job skills. Arguments include that they promote rote memorization over genuine problem-solving, are often biased, and feel irrelevant to day-to-day development work.2. The Defense: Conversely, the defense is that they serve as a necessary filter for raw problem-solving ability, logical reasoning, and demonstrate a candidate's commitment to preparation.Beyond that main debate, several interesting sub-topics have emerged:The role of constraint solvers: A controversial point, with some arguing they show a candidate's ability to use powerful tools, while others feel it sidesteps the core coding challenge.Dynamic Programming (DP): Frequently mentioned as a key interview pattern, though there's a running discussion on whether mastering complex DP is as practically useful as identifying and fixing more common N² inefficiencies.Pitfalls of Greedy Algorithms: The limitations of greedy approaches (like in the classic coin change problem) are being used as examples of why more robust methods are sometimes necessary.Hope this summary is helpful for navigating the conversation!
  • atilimcetin
    Whenever constraint programming languages come up, you can’t miss mentioning Håkan Kjellerstrand. He’s put together an amazing collection of problems and examples—including plenty for MiniZinc—on his site: https://www.hakank.org/minizinc/
  • Stevvo
    The first example doesn't make a lot of sense, because coins only ever exist in "well-behaved" denominations. There is no currency with a nine unit coin.
  • tbmbob
    > Now if I actually brought these questions to an interview the interviewee could ruin my day by asking "what's the runtime complexity?"This completely undermines the author's main point. Constraint solvers don't solve hard leetcode problems if they can't solve large instances quickly enough.Many hard leetcode problems can be solved fairly simply with more lax runtime requirements -- coming up with an efficient solution is a large part of the challenge.
  • RomanPushkin
    - Constraint solvers? That's a nice concept, I heard about this once. However, for the purposes of the interview, let's just write some Python code, I wanna see your way of thinking...(I think it's almost impossible to convince your interviewer into constraint solvers, while the concept itself is great)
  • binarymax
    A loonnngggg time ago when I was green, and wasn't taught about constraint solving in my State University compsci program, I encountered the problem when trying to help a friend with his idea.He wanted to make an app to help sports club owners schedule players for the day based on a couple simple rules. I thought this was going to be easy, and failed after not realizing what I was up against. At the time I didn't even know what I didn't know.I often look back on that as a lesson of my own hubris. And it's helped me a lot when discussing estimates and timelines and expectations.
  • ripped_britches
    I would be blown away if a candidate solved it using DP and then said “but let me show you how to use a constraint solver”. Immediate hire.
  • itissid
    Long time ago, just for fun, I wrote a constraint solver problem that could figure out which high yield banks to put money into that were recommended on doctor of credit(https://www.doctorofcredit.com/high-interest-savings-to-get/) based on <= `X` money and <= `Y` # of transactions on debit cards maximize the yield and other constraints(boolean and real valued)I played it for a while when interest rates were really low and used the thing for my own rainy day savings(I did get tired changing accounts all the time)
  • drob518
    SAT, SMT, and constraint solvers are criminally underutilized in the software industry. We need more education about what they are, how they work, and what sorts of problems they can solve.
  • jcul
    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)?
  • krosaen
    I find this post interesting independent of the question of whether leetcode problems are a good tool for interviews. It's: here are some kinds or problems constraint solvers are useful for. I can imagine a similar post about non-linear least squared solvers like ceres.
  • amai
    The documentation for Googles OR tools comes with many interesting examples of constraint problems, e.g.https://developers.google.com/optimization/lp/stigler_diet
  • j2kun
    > The real advantage of solvers, though, is how well they handle new constraints.Well said. One of the big benefits of general constraint solvers is their adaptability to requirements changes. Something I learned well when doing datacenter optimization for Google.
  • qnleigh
    I agree with the other comments here that using a constraint solver defeats the purpose of the interview. But this seems like a good case for learning how to use a constraint solver! Instead of spending hours coding a custom solution to a tricky problem, you could use a constraint solver at first and only write a custom solution if it turns out to be a bottleneck.
  • cobbzilla
    Here’s my empirical evidence based on several recent “coding session” interviews with a variety of software companies. Background: I have been developing software for over 30 years, I hold a few patents, I’ve had a handful of modestly successful exits. I kind of know a little bit about what I am doing. At this stage in my career, I am no longer interested in the super early stage startup lifestyle, I’m looking at IC/staff engineer type roles.The mature, state-of-the-art software companies do not give me leetcode problems to solve. They give me interesting & challenging problems that force me to both a) apply best practices of varying kinds and yet b) be creative in some aspects of the solution. And these problems are very amenable to “talking through” what I’m doing, how I’m approaching the solution, etc. Overall, I feel like they are effective and give the company a good sense of how I develop software as an engineer. I have yet to “fail” one of these.It is the smaller, less mature companies that give me stupid leetcode problems. These companies usually bluntly tell me their monolithic codebase (always in a not-statically-typed language), is a total mess and they are “working on domain boundaries”.I fail about 50% of these leetcode things because I don’t know the one “trick” to yield the right answer. As a seasoned developer, I often push back on the framing and tell them how I would do a better solution by changing one of the constraints, where the change would actually better match the real world problem they’re modeling.And they don’t seem to care at all. I wonder if they realize that their bullshit interviewing process has both a false positive and a false negative problem.The false negatives exclude folks like myself who could actually help to improve their codebase with proper, incremental refactorings.The false positives are the people who have memorized all the leetcode problems. They are hired and write more shitty monolithic hairball code.Their interviewing process reinforces the shittiness of their codebase. It’s a spiral they might never get out of.The next time I get one of these, I think I’m going to YOLO it, pull the ripcord early and politely tell them why they’re fucked.
  • tannhaeuser
    Here's an easy ad-hoc Prolog program for the first problem: % Given a set of coin denominations, % find the minimum number of coins % required to make change. % IE for USA coinage and 37 cents, % the minimum number is four % (quarter, dime, 2 pennies). num(0). num(1). num(2). num(3). num(4). num(5). ?- num(Q), num(D), num(P), 37 is Q * 25 + D * 10 + P You can just paste it into [1] to execute in the browser. Using 60 as target sum is more interesting as you can enumerate over two solutions.(Posting again what I already posted two days ago [2] here)[1]: https://quantumprolog.sgml.net/browser-demo/browser-demo.htm...[2]: https://news.ycombinator.com/item?id=45205030
  • deepsun
    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.
  • thomasahle
    Interview:> We can solve this with a constraint solverOk, 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?
  • theendisney
    coins = [100,50,25,10,5,1] change = 1234; result = [0,0,0,0,0,0]; for(i=0:i<coins.length;i++){ while(change>coins[i]){ result[i]++; change-=coins[i]; } } //[12,0,1,1,4] Coudnt help myself sorry
  • cerved
    MiniZinc is a really great modeling language for constraint programming. Back in August I gave a talk at NordConstNet25 on how we used it to build a product configurator in what's (probably) the worlds largest MiniZinc modelhttps://pierre-flener.github.io/research/NordConsNet/NordCon...
  • faangguyindia
    I avoided all this just by becoming a contractor, i ship solution, no me tests me for leetcode ability
  • FilosofumRex
    SAT & CSP are criminally under utilized in CS classes, because profs have no clue about them.That's why in so many industries they prefer to hire engineers and OR grads and teach them python, than hire SWE and teach them modeling
  • treenode
    It would have been worthwhile if this article had briefly touched upon how the constraint solvers are implemented, rather than avoiding this altogether
  • Jun8
    An interesting meta problem is to determine antagonistic set of denominations, like the [10,9,1] example given in the post, to maximize the number of coins selected by the gradient method.
  • dataflow
    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.
  • gnarlouse
    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.
  • SCLeo
    Does using a constraint solver actually solve the question under the time ... constraints?If not, how can you claim you have solved the problem?
  • jameslai
    Terrible question for an interview, and further highlights how our interviews are broken.Greedy algorithms tell you nearly nothing about the candidate's ability to code. What are you going to see? A single loop, some comparison and an equality. Nearly every single solution that can be solved with a greedy algorithm is largely a math problem disguised as programming. The entire question hinges on the candidate finding the right comparison to conduct.The author himself finds that these are largely math problems:> Lots of similar interview questions are this kind of mathematical optimization problemSo we're not optimizing to find good coders, we're optimizing to find mathematicians who have 5 minutes of coding experience.At the risk of self-promotion, I'm fairly opinionated on this subject. I have a podcast episode where I discuss exactly this problem (including discuss greedy algorithms), and make some suggestions where we could go as an industry to avoid these kind of bad-signal interviews:https://socialengineering.fm/episodes/the-problem-with-techn...
  • chipsrafferty
    Would love to know how to actually assess the runtime complexity of constraint solvers like this.
  • BhavdeepSethi
    It's insane how many of these new "AI" companies don't let you use AI or even your own IDE for coding interviews. And most questions from such companies are LC type problems so they know any AI tool can one shot it.
  • swiftcoder
    > Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram.Maybe it's my graphics programmer brain firing on all cylinders, but isn't this just a linear scan, maintaining a list of open rectangles?
  • wolvesechoes
    Whoever agrees to do LC problems during interview has zero dignity.
  • whatever1
    I tried a couple of times long time ago to solve them with cp/integer programming.The interviewers were clueless so after 10 minutes of trying to explain to them I quit and fell back to just writing the freaking algo they were expecting to see.
  • phendrenad2
    So LeetCode has fallen into the same trap as ProjectEuler (anyone remember that?)
  • taylodl
    Use the right tool for the right job!
  • RagnarD
    Nice post, I wasn't aware that there were so many dedicated constraint solving systems.
  • notemap
  • aeternum
    You: Oh I know, I can use a constraint solver for this problem!Interviewer: You can't use a constraint solver
  • LordDragonfang
    > This was a question in a different interview (which I thankfully passed):> Given a list of stock prices through the day, find maximum profit you can get by buying one stock and selling one stock later.It was funny to see this, because I give that question in our interviews. If someone suggested a constraint solver... I don't know what I'd have done before reading this post (since I had only vaguely even heard of a constraint solver), but after reading it...Yeah, I would still expect them to be able to produce a basic algorithm, but even if their solution was O(n^2) I would take it as a strong sign we should hire them, since I know there are several different use cases for our product that require generalized constraint solving (though I know it by other names) and having a diverse toolset on hand is more important in our domain than writing always-optimal code.
  • meindnoch
    Any problem can be solved by a sufficient number of nested for loops.(if you have enough time)
  • jongjong
    My Leetcode ability is unpredictable. I either ace the test or I can't finish it in time. The only way to make outcomes predictable is practice, but I have too much agency and not enough time for that.Leetcode requires a very different set of skills from software engineering. Software engineering isn't so much about solving puzzles as it is about making good decisions. It's about knowing what's important and knowing where the boundaries are. It's about anticipating problems in their broadest form; creating just the right amount of flexibility and allowing the solution to solidify as your understanding of the problem deepens.
  • Herring
    Reminder that the research says the interview process should match the day to day expectations as closely as possible, even to a trial day/week/month. All these brain teasers are low on signal, not to mention bad for women and minorities.
  • zzzeek
    I've never heard of a "dynamic programming algorithm". Read wikipedia and it seems to mean....use a recursive function? The coin problem is an easy recursive problem (I just wrote the code for it to make sure my old brain can still do it).
  • guluarte
    Most leetcode problems fall into the same ~15 patterns, and hard problems most of the time require you to use a combination of two patterns to solve them.
  • non_aligned
    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
    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.
  • cratermoon
    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
    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
    > 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.
  • scotty79
    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
    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.
  • gnatman
    “Many hard problems are, to me, quite easy”
  • garrettgarcia
    "Follow-up question since you solved that so quickly: implement a constraint solver."
  • techlatest_net
    [dead]
  • afro88
    A little off topic, but I don't know much about greedy algorithms or dynamic programming. I got curious. This conversation was very insightful and now it's very clear in my mind: https://chatgpt.com/share/68c46d0b-8858-8004-aa03-f7ce321988...