Live data from Hacker News

Algorithms Interviews: Theory vs. Practice (2020)

danluu.com

61–69 of 69 posts

Re: Algorithms Interviews: Theory vs. Practice (2020)

#61

I wrote an HN submission somewhere about the biases I've seen in algo interviews. One thing is they love questions that can be solved with some small twist on BFS or DFS, usually one that's a lot easier if you're doing it non-recursively. I've gone through entire multi-round interviews like that.

Breadth-First Search or Depth-First Search, I think. It took me too long to guess those initialisms.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#62
post #42

Earlier quoted context omitted.

I agree at the level of source code, but sometimes algorithm skills affect the whole architecture. Even simple things like where certain data and logic would optimally exist can have cascading and compounding consequences for the whole rest of the system. To see better solutions, you have to know what's possible with algorithms and data structures. To give a contrived example that I think should make sense no matter…

Yes, I absolutely buy the argument that doing things the optimal way will make a difference at scale. When some method is being called, or some data structure is being used, trillions or quadrillions of times (all the users of facebook/tiktok/etc. clicking on something / using a feature) - even small optimizations can add up quickly, which can obviously mean more compute or storage. But I do not believe that you will…

> And at companies that operate at such scale, there are many, many safety measures put up - not to mention the continuous performance analysis and reviews.

If I can see these issues hit at multiple separate FAANG companies famed for their algorithm interviewing then we still don't have enough safety measures. As long as a spectrum of individual algorithm skill goes as low as X, there's always a non-zero probability you'll have a whole team around that level X. A larger institution just creates more opportunities for random teams to be low outliers just like you'd hope some would be high outliers.

Sure, these situations shouldn't last forever, sooner or later the problem will be bad enough that someone has to come in and rescue the project. I've been that person multiple times [1], so some might say maybe I've just seen the worst of it and my experience isn't universal, but ask yourself how likely it is that I've had to save multiple large projects across multiple large companies if there isn't enough of this in the industry to go around.

It's always a total disaster when you get to a project like that. There'll be one "worst" algorithm but there'll also be many other terrible algorithms. I wish I could say they were only inefficient; people who don't understand algorithms usually produce plainly incorrect algorithms, not just inefficient ones, because algorithm knowledge is required for both. Even if they bother to write tests, which is far from a given, they won't think of the algorithmic edge cases most deserving of tests.

If you're very lucky, you can find a way to regenerate production data to fix whatever errors were introduced by the incorrect algorithms. Often this is impossible because the original inputs were not saved because of the assumption that the algorithm was correct even if inefficient. We can talk all we want about how there should be safety nets for these things, but there's no denying incorrect code does sometimes end up in production even at a large scale.

[1] I'm really not even that good at algorithms. I can do every day in Advent of Code without spoilers, but nowhere near a competitive level, and not always the most efficient algorithm for a given day. It turns out that's still far more algorithm knowledge than the average senior FAANG engineer who doesn't even attempt AoC because they're too busy step-debugging their last dumpster fire.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#63
post #19

If you don’t know Dan or haven’t read enough of his work to get this, > I can't pass algorithms interviews! When I say that, people often think I mean that I fail half my interviews or something. It's more than half. is insane. Dan’s day job is (or was, on the occasions that I’ve worked with him) to identify and solve the weirdest, gnarliest scaling and performance bugs in extremely large systems. If Dan isn’t passin…

In my experience, algorithmic interviews work great for people that A) Are deeply interested in the topic. If you dabble in competitive programming, then these interviews should be a breeze. B) Young people out of college, with a fresh memory of data structures and algorithms classes. C) High IQ individuals. This one might be controversial, but I've met plenty of people that were just intellectually sharp enough to d…

You forgot first and foremost that a percentage of people just show up with the right answer. This has always bothered me about "brain teasers". Just testing for "have I seen this before".

Re: Algorithms Interviews: Theory vs. Practice (2020)

#64
post #10

Earlier quoted context omitted.

Annoying counterpoint, of course, I've seen senior developers also stall out on avoiding quadratic code to the point that they didn't get the code delivered and then the project got scrapped. The most widespread failure I have seen, by far, is to write code that is so abstracted out that it isn't really clear on how to get the necessary parts inline to get at efficient code. You'll have an obvious path on how to load…

I’m curious for more details. I imagine this has to be more interesting than “Just write the double for loop.” “No.” “Ok I guess we’re canceling this project.”

Yeah, it was rarely that silly. Usual thing I'm thinking of are the designs where folks think they can make something like facebook messenger with 200ms latency in the system. You know, "by design." (Of course... I swear that was an interview question I was given once.)

What you wind up with is someone designing a giant system from parts they have read about that, honestly would probably work. However, it would also require retouching pretty much every system in the company to get things aligned. Which, isn't likely to ever happen.

Put a different way, the longer a project spends in design phase, the higher the chance it will not get completed. And all too often people will spend a ton of time in design looking for ways to make sure what they are building will scale to success level loads.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#65

Earlier quoted context omitted.

That is pretty much my stance, too. I've seen a lot of critical fuckups in my years, but I have yet to see someone fuck up everything by using a woefully unsuitable algorithm. That, of course, does not mean that it doesn't happen - could very well be the case at the type of companies I haven't worked for, where performance is absolutely critical...but I have a hard time believing those places don't have safety guards…

> I've seen a lot of critical fuckups in my years, but I have yet to see someone fuck up everything by using a woefully unsuitable algorithm. This bears repeating. With the exception of very niche applications, such as AAA games and scientific computing, the only realistic impact of picking a sub-optimal algorithm is slightly higher CPU utilization rates and background tasks taking a bit longer to finish. This means…

> the only realistic impact of picking a sub-optimal algorithm is slightly higher CPU utilization rates and background tasks taking a bit longer to finish.

At FAANG scale this couldn't be further from the truth. Let me give an example from my own work. With a tiny bit of rewording, it could cover at least two other examples I have worked on as well, at multiple companies, so I think it generalizes well enough.

A global control system needed to generate its control signals algorithmically because it had to optimize an objective worth billions per year. The dataset had grown to take over 8 hours to process, which was just barely tolerable in fair weather, it became a batch job. This was doubling every year, mind you.

Sometimes tactical changes were required on short notice, e.g. a datacenter outage required failing over to another datacenter and re-calculating the optimal way to meet those objectives, not just for resource costs but user experience. Here it was bad enough taking 8 hours, and nobody wanted to see it double in the following year.

In a few days I rewrote this tool to give the same optimal results in under 5 minutes. Now every time a tactical change is needed, it's no big deal at all. There's no doubt this saved millions already, and as the dataset continues to grow, taking 15 minutes would still be a lot better than taking 24 hours.

Another case was even more extreme but harder to compare. Re-generating all control plane data from management plane intent would have taken at least several days with the old algorithm, but this was so impractical that nobody ever did it and we never had a number for it. I made it take less than a second total, completely changing how the entire architecture, implementation, operations, observability, scale, availability, latency, etc. hinged around the new algorithm. It was the single biggest improvement to a large platform that impacted the entire company, and it's a big company.

I have several such cases. Sometimes they're offline tools that occasionally end up in the critical path of an operation during an incident, sometimes they're in the critical path of serving user requests or in a control system affecting the availability and user experience of other user-facing services. None of these were "slightly higher CPU utilization rates", they were a quantative improvement to performance so great that it made a qualitative improvement to what was possible.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#66
post #9

I have definitely seen senior developers put quadratic and even exponential algorithms into production and cause global outages. Code review didn't help, because their code was reviewed by other people who were interviewed to the same low standard. I continue to insist on algorithm & data structure interviews for software engineer candidates. Not every project needs them as much, but in large enough institutions, eve…

> I continue to insist on algorithm & data structure interviews for software engineer candidates. Not every project needs them as much, but in large enough institutions, every engineer is likely to run into at least one project that does. If they can't figure it out and can't get help from someone who can, their weak solution can easily cost the company and its other engineers far more than it would have cost to inte…

> Using algorithms&data structures trivia in interviews

I never said trivia. By definition, trivia is stuff that is not important. I interview for things that are important to the work we do, and I give plenty of hints along the way to give a candidate a chance to show their reasoning abilities even if they have gaps in their knowledge or memory. This is what critics of algorithm interviewing conveniently ignore to make the interview seem unfair and unreasonable.

If you had a bad interviewer I'm sorry to hear that. Formal interview training in places like Google explicitly includes how to hint and unblock people effectively, and hiring committee feedback-on-feedback can instruct interviewers how to be more fair and better reflect the candidate's potential. Maybe your interviewer did a bad job and later received that feedback, but it had already soured your perception of algorithm interviews.

It's also a total myth that candidates are completely rejected because of one bad algorithm interview. If you have a day of five interviews, your success is not an AND() of the five, but it's also not an OR(). Whoever looks at the feedback weighs the various positive and negative signals to determine if it's a fit for the role. Skills in some areas can outweigh skills in other areas. Algorithms are one of those areas for a reason but it's still only one area and probably only one or two of the five or more interviews people will do.

If you know a better way to interview for these skills before hiring someone, please tell the rest of us and change the industry for the better. Until then, this seems to be the best we can do.

If your organization has very different needs, you can interview your candidates however best meets those needs. I know my organization needs algorithms and data structure skills, not just trivia but actual fundamental skills that generalize to novel problems we encounter along the way, and I'm going to keep interviewing for those skills. It's still just one interview out of several, and we've hired people that totally flunked my interview, so I'm not even gatekeeping, I'm giving the hiring team the signal they asked me to give them and the rest is up to them.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#67

Question based on some surprising-to-me chatter in a thread some weeks back about interviews: When people claim that some shocking proportion of allegedly-accomplished candidates can’t write basic code to perform even a simple task on a whiteboard—do they mean pseudocode, or something akin to that? Or are they counting off points for getting actual syntax wrong? Because I’ve been paid to write code for more than two…

Just one example, but I was failed on a technical I took recently. It had a runtime, so not a whiteboard. But the editor I had to use provided no checking and I only found out after minutes of work that debugger breakpoints were not supported (the interviewer had not used them before)

So I failed the technical as I had to spend like a substantial amount of a 45m session console logging out values and experimenting as I went. It turned out I missed a few characters in my code. I was pretty beside myself.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#68
post #65

Earlier quoted context omitted.

> I've seen a lot of critical fuckups in my years, but I have yet to see someone fuck up everything by using a woefully unsuitable algorithm. This bears repeating. With the exception of very niche applications, such as AAA games and scientific computing, the only realistic impact of picking a sub-optimal algorithm is slightly higher CPU utilization rates and background tasks taking a bit longer to finish. This means…

> the only realistic impact of picking a sub-optimal algorithm is slightly higher CPU utilization rates and background tasks taking a bit longer to finish. At FAANG scale this couldn't be further from the truth. Let me give an example from my own work. With a tiny bit of rewording, it could cover at least two other examples I have worked on as well, at multiple companies, so I think it generalizes well enough. A glob…

> At FAANG scale this couldn't be further from the truth.

Here's the problem with this blend of specious reasoning. Even without questioning your claims, your example is based on a scenario consisting of a niche of niches whose relevance is limited to rare corner cases which have virtually no expression on the real world.

It's like trying to extrapolate optimization details from Formula 1 as something relevant for the design of a Volkswagen hatchback.

I mean, I worked at a FAANG on flagship services that virtually the whole world used, and I can tell you as a matter of fact that the vast majority of real-world FAANG services do not qualify as your hypothetical FAANG scale.

That's where you're basing your anecdotal example.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#69

Earlier quoted context omitted.

In my experience, algorithmic interviews work great for people that A) Are deeply interested in the topic. If you dabble in competitive programming, then these interviews should be a breeze. B) Young people out of college, with a fresh memory of data structures and algorithms classes. C) High IQ individuals. This one might be controversial, but I've met plenty of people that were just intellectually sharp enough to d…

You forgot first and foremost that a percentage of people just show up with the right answer. This has always bothered me about "brain teasers". Just testing for "have I seen this before".

I once had an interview for an internal transfer where the problem they gave me was one that we’d spent 6 years worth of senior staff engineers solving. Not sure I got to the same answer they did in my allotted 30min.
Post reply on HN