Top
Best
New

Posted by mpweiher 1 day ago

Many hard LeetCode problems are easy constraint problems(buttondown.com)
569 points | 471 commentspage 5
notemap 23 hours ago|
https://codeforces.com/problemset/problem/1889/D
jameslai 1 day ago||
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 problem

So 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...

avgDev 1 day ago|
My best interview consisted of: -what projects have you done

-what tech you worked with and some questions about decisions

-debugging an issue they encountered before

-talking about interests and cultural fit

Instant green flag for me. Too bad that after receiving my offer covid happened and they had a hiring freeze.

ryanjshaw 1 day ago|||
This is how I prefer to interview. I don’t understand the mindset of LeetCode interviewers. It’s a weak signal because it’s easily gamed (false positives), and has misses too many strong candidates who have better things to do in their spare time (false negatives, bias towards one type of candidate -> lack of diversity in experience).
scotty79 19 hours ago|||
I've seen some cases where someone bragged about projects they participated in but then struggle to write a simple loop.

You can try to sus out smooth talking faker or just tell them to write a thing and then talk only after they demonstrate basic comprehension.

aeternum 19 hours ago||
You: Oh I know, I can use a constraint solver for this problem!

Interviewer: You can't use a constraint solver

LordDragonfang 1 day ago||
> 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.

tracker1 1 day ago|
Something that works poorly is often better than something that doesn't work in an instant. This is what I have to tell myself every time I step into a massive, excessively complex mess of a codebase. Many business rules aren't clearly defined ahead of time in a way that always translates well to the code and starting over is a mistake more often than not imo.

Update... refactor... update... break off... etc. A lot of times, I'm looking at something where the tooling is 8+ years old, and the first order of business should be to get it working on a current and fully patched version of whatever is in place... replacing libraries that are no longer supported, etc. From there, refactor what you can, break off what makes sense into something new, refactor again. This process, in my experience, has been far more successful than ground up, new versions.

I say this while actively working on a "new" version of a software. New version being web based, "old" version being a winforms VB.Net app from over a decade ago. Old version has bespoke auth, new verion will rely on Azure Entra... Sometimes, starting over is the answer, but definitely not always.

jongjong 7 hours ago||
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.

meindnoch 1 day ago||
Any problem can be solved by a sufficient number of nested for loops.

(if you have enough time)

6510 12 hours ago||
One level of nested for loop for each type of coin. (Run them until i*coin is larger than the input)

Populate a 2d lookup array. $7,50 becomes arr[750] = [7,1,0,0,0,0] which represents [7x100,1x50,0x25,0x10,0x5,0x1]

With each loop check if the array entry exists, if so check if that number of coins is larger. [7,1,0... is better than [7,0,2...] because 8 is a better solution than 9!

scotty79 19 hours ago||
And a stack.
Herring 1 day ago||
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 23 hours ago||
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).
Jtsummers 22 hours ago||
It's usually covered in a first or second year algorithms course. It's a recursive problem definition paired with tabling to eliminate redundant work. Critically, the recursive subproblems have to be overlapping (they'll do some of the same work as the other recursive steps) to see any benefit. You can implement it top-down and add a cache (memoization) or you can implement it bottom-up and fill out the table iteratively rather than through recursion.

If you just implement it recursively without tabling then you end up re-doing work and it's often an exponential runtime instead of polynomial.

To clarify on overlapping, consider Fibonacci:

  F(n) = F(n-1) + F(n-2) # and the base cases
F(n-1) includes F(n-2) in its definition, and both F(n-2) and F(n-1) include F(n-3). If you implement this naively it produces an exponential runtime. Once you add the table, the single initial recursive call to F(n-1) will end up, through its chain of calls, storing the result of F(n-2) and now the implementation is linear instead of exponential.
joz1-k 22 hours ago|||
> Read wikipedia and it seems to mean....use a recursive function?

Yes, that's one (common) approach to dynamic programming. The recursive function call are memoized so that previous calculations are remembered for future function calls. Overlapping subproblems become trivial if you can reuse previously computed values. The recursion with memoization is top-down dynamic programming.

scotty79 19 hours ago||
So all in all pretty basic stuff. Why would anyone worth their salt should have problem with that?
dgacmu 16 hours ago||
The hard part is realizing that the problem you're solving efficiently maps to a dynamic programming algorithm. You have to spot the opportunity for sub-problem reuse, or else the solution looks something like cubic or exponential (etc.)
scotty79 4 hours ago||
> You have to spot the opportunity for sub-problem reuse

Which sounds exactly like what developers do in non boring parts of our job. If anything, the problem is that tests are being tightly timed, while time budget for real world task of this kind is usually more generous. On the other hand business time that company spends with inefficient solution or without one costs a lot of money so I can't blame companies for wanting employee who at least on toy problems can do that quick.

runeblaze 16 hours ago||
The coin problem is like the intro to it. Try some of the codeforces one :skull:
guluarte 1 day ago||
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 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.

More comments...