Data structures and algorithms I actually used while working at tech companies
blog.pragmaticengineer.com
blog.pragmaticengineer.com
I did not get the job at Google.
I do make sure as a more senior engineer at my current company I use what leverage I have to make sure other interviewers don't ask pointless questions like this.
If your question requires having previously memorized or being able to come up with some tricky algorithm on the fly in 45 minutes and code a solution using it, your question is probably bad.
I get why they ask them - they're easy to ask, they're easy to score, and when your question inevitably gets burned because someone posted it all over the internet in their blog post titled "How I got a job at Google!!" and then bumped way up the list on hackerrankcode-whatever I forget the websites... it's easier to come up with a new one, because you just pick a new esoteric algorithm and ask that.
And honestly, coming up with interview questions can take awhile. When you have 5 or 6 very calibrated questions and all of them get burned and banned in a one quarter span, you now have to spend the better part of a whole workweek, plus dozens of more interviews coming up with new questions and recalibrating.
But, I just refuse to ask those types of questions anymore. They really don't give useful signal. The only three bits of signal you get are "does the candidate already know this algorithm (or are they a supergenius who just figured it out under time pressure)? can they communicate it to another engineer? can they write code?"
Importantly if the answer to the first question is no, then you get zero signal on the other two parts. That basically means as an interviewer you just failed your job.
> It's 2140 AD, New York is under water up to X feet high. Buildings have been retrofitted with <magical-ish material> to withstand the water. You are in charge of keeping your building dry. If water gets in and damages the foundation, a few thousand people die or become homeless.
> Design a system that ensures that doesn't happen.
How candidates approach this, how they think about redundancy, how they deal with additional constraints or extra scenarios thrown at them tells a lot about how they approach things. The question is not about software (explicitly) on purpose so that it gets people out of the coding mindset.
With more software-focused systems you always get candidates who starts writing code and designing objects and classes and stuff. No, I want you to design a system. Stop writing code.
The reason this question is unburnable is that there's no right answer. You're being asked to show how you work through an abstract problem and design a solution. You aren't being asked for an answer.
So far everyone who did well on that question has turned out to be a great engineer. Whether they were fresh out of college (and learned a lot fast) or they were already experienced.
Why not just summarizes the traits of the technical skills you expect from the candidate, lay it out, and come up appropriate questions for each interview?
General software engineering interview does not work. But there can be more specific measures to improve the experience.
That won't work; it's aimed at a different kind of skill.
The skill the GP is looking for is ability to solve a problem you have never seen before, for a problem that bears little resemblance to anything you've done before, by transferring your existing general problem solving skills. It's a test of your ability to solve new things, which is a capability the company finds useful.
This is a very useful skill, and you can learn to do it better, but it's not a "technical" skill as we usually mean it. However it is one of the things which might be associated with "great engineer".
Listing technical skills and testing them will not tell you if the candidate has developed the above capability.
Correct.
I work with early-ish stage startups. There's always a library that solves any given known problem. We don't have the scale or nuance to need to reinvent the wheel.
Where I really need engineers to shine is in solving the parts that don't have a library because we've stumbled onto something new. Or at least something new to the team. Or the way we've cobbled libraries together creates something new.
The important work is the work you haven't done before. We're engineers not line cooks.
November should involve completely different work and a whole new set of problems than February. If you're still doing the same thing you did in February, something's gone wrong.
I do worry about asking questions that give candidates extremely large advantages if they have certain backgrounds. For example someone coming from mech, civ, or petroleum engineering will get a huge leg up on that question.
It is also worth noting that the structure for interviewing at a company with 30-50k+ engineers is different than the structure you need for interviewing at a company with <<1k engineers.
I'm done. Give me my paycheck.
That sounds expensive. Do we need to do that? Does it solve the problem better? Does it maybe create a worse solution? How would you find out?
> Have the people who maintained each individual building form a team that can keep an eye on sections in shifts?
How would you make this less time intensive? Can you use automation?
> If we have enough magic material, build a double wall system for breaches?
Is there a cost-benefit analysis you can run here? How would you find out? Should we keep adding walls ad infinitum or does each additional wall have diminishing returns?
> I'm done.
wrong.
But that is probably not the point. In order to build wall around the city, you need to have power or consensus in society to deliver this decision. And achieve that in reasonable time might be unreal for someone in charge of one building.
I'm not convinced this offers a useful selection criteria other than boosting your unconscious bias on who "seems smart", but on the other hand I'm also not convinced it's any worse than the standard modern Leetcode interview.
"How would you fill this airplane with golf balls?" is a fantastic question. If the candidate doesn't reply with "Why? What are you really trying to achieve?", they're gonna do poorly in modern software development.
Caveat: This does not apply to junior positions where you are expected to bang out code based on super fleshed out requirements and constraints.
The end result being off is fine if I am being graded based on my thought process, but a disaster if I am being graded at having an idea of the size of airplanes before walking into the interview.
I hire people to track objects via computer vision. I ask them "hey, here's a system I want, what approaches would you take", and explain that this is a 3 year research project, of course they will be giving simplistic and wrong answers and there is knowledge asymmetry here, but I'll inform you as you go as to what works and not. "Optical flow". Okay, why? What's the general algorithm? Okay, so it turns out it doesn't work in our situation because X,Y,Z. Any ideas on what you'd look at next. And so on. Because that is exactly how my day-to-day conversations and work goes. Bounce ideas off of co-workers, latch onto something that seems promising, explore, maybe it works, maybe it fails. If it fails, what does that tell you about what to try next. Along the way you can have them code a tiny piece of something they mentioned if you want to see some code. But basically you are seeing if they understand the domain you are working in (which is not golf balls on airplanes), if they have some (not comprehensive) knowledge of the domain, and if they understand book solutions don't necessarily deal with the messiness of the real world and can adapt approaches to appropriately (i.e. a 20sec/frame algorithm is not going to cut it when I need 180fps).
It bothers me that this is still somewhat unfair due to the vast information asymmetry, but I try to deal with that. And my own biases can creep in. Are they mostly using 1980s style image processing techniques? Do they understand Bayes? Do they throw ML at problems that aren't tractable that way? It's unlikely that their past experience & preferences reflect exactly what we need. What is important - can they adapt, or even better, communicate why my choices are wrong and theirs are right (I don't need a robot to grind out code reflecting my ideas, I need them to figure things out and solve things in a fairly scientific manner).
So those are the questions I try to ask. I have no evidence that I get it right, but I haven't been disappointed with the hires.
Mind you, I’m not saying you’re wrong to discount people who fail to stay abreast in their field, just know that sometimes there is wisdom in ignoring popular trends, or revisiting old techniques that might benefit from a different landscape.
Some candidates will simply freeze if they don't know the answer. Some will try to estimate the dimensions and come up with an estimate. I think Google wanted to try to anticipate what a person would do when stuck by asking these types of questions.
Sure, you may say that everyone who does well turns out to be a great engineer. I'm sure Google says the same thing about their algorithm trivia tests. Presumably the goal is to move away from these seemingly arbitrary and irrelevant tests. Just replacing one arbitrary and irrelevant test with another isn't improving the state of things.
In the interview I play the domain expert.
This is exactly what your job will look like: collaborate with domain experts, use your software skills, solve real world problems.
I don’t need an engineer who can build a queue. I need an engineer who can use a queue.
The key phrase is yours: "real world problems". Your hypothetical misses that by a generous mile.
And I apologize about this but we're discussing actual issues with software recruitment:
One major problem noted by senior engineers subject to these interviews is the competence level of the interviewer. I had this one guy, a "principal engineer", ask me about "Optimistic locks" as his initial query into my knowledge of concurrent systems. It took a lot of self-restraint to not blurt out "You mean optimistic locking?"
It is amazing to me that we somehow managed to hire very good software workers in the 90s without any of these shenanigans. One thing that does stand out from my memory of the 90s: we had senior colleagues (with literal white hair) in senior engineering positions. Go figure.
Here’s another idea: have them write software. Not algorithm trivia, but actual software. Keep the scope small so there isn’t an onerous time commitment and have them explain their choices.
Well, if we live in a world with magic, I would just use the magic material to make a machine that removes the water magically.
I feel like they don't realize that this is the goal they're calibrating these questions toward, though. If they did, they wouldn't require the "from memory" component—instead, they'd break the question into two parts:
1. tell me what algorithm you would use to solve this problem; or, failing that, tell me what criteria you'd use to select the best algorithm for solving this problem out of a set of candidate algorithms.
2. Here's a journal paper, explaining a particular data structure + set of algorithms that can† be used to solve the problem we're talking about. All the algorithms in the journal paper are in that sort of declarative, math-proof-phrased pseudo-pseudo-code form. Now take this journal paper and turn it into an implementation in your language of choice. Explain your thinking as you go.
† The paper chosen is not the one corresponding to the algorithm the candidate chose; nor is it the one corresponding to the algorithm that's "right" to pick for solving the problem. It is, in fact, randomly-chosen from the pool of sub-optimal solutions to the problem, filtered for the ones that get rarely used in practice and so have no easy non-journal-paper presentations of a reference impl laying about on the web to study. Alternately—if the interviewer has enough time to explain a second problem—it could even be a paper randomly-chosen from the pool of all algorithms papers!
Benefits:
• Both task 1 and task 2 are things "senior" engineers do every day in the real world.
• There's no component of memorization; the step "between" step 1 and step 2, where you'd look up the journal paper corresponding to the algorithm you thought of, is dropped.
• You can't really "burn" either task.
That's not what I see in practice though. Not remembering the whole algorithm at best ends up wasting half of the interview (code the remainder in 20 minutes??), and at worst gets explicit language from the interviewer like "TC couldn't figure out <insert tricky algorithm> and I had to explain the algorithm to them explicitly, WEAK/BORDERLINE on algorithms".
I should also say, I dislike doing any engineer interviews that are purely talk-about-algorithm without any code, because I've interviewed a disturbingly large number of candidates who cannot write about 10 lines of mostly-bug-free code with a single state variable and like one loop, in 30+ minutes.
It is kind of hilarious to get an algorithm problem which took eminent computer scientists years to solve the first time. "Why yes, I am Donald Knuth/Edsger Dijkstra/et al. – only smarter, luckier, and much faster!"
As you note, the initial question is basically "how well do you recall the solution to this problem?"
All of these 'tricky' exam style questions don't show a thing about the person sitting in the interview room.
I've hired based on a good discussion alone, without code... And got a great engineer.
So, you can ask to see candidate's existing code if you work at a small enough shop and/or don't care about missing out on candidates who don't have shareable code. But if you are trying to hire at a larger scale, it does not work.
Many great hiring schemes work until a certain scale and then they fall apart. Some hiring schemes also severely tilt your candidate pool towards a certain subset of the population. I'm sure whiteboard style interviewing also has similar issues.
If you looked over my github, you would see most of my commits are ones that, at work, I wouldn't accept from anyone. The code is sloppy, there are no tests, it looks like someone was just trying to get something working as quickly as possible with no thought for maintainability or understandability. But, of course, that's exactly what I was doing! When I code in my spare time, I'm solving problems that I've run into in my spare time, and I approach it very differently from in my work life. The constraints are different, and so the solutions are different.
However, that was not the case. The interviewer wanted me to code it all out over Google Docs, but I didn't remember the exact algorithm so I basically had to re-figure it out on the fly, which took most of the interview (I even similarly mention "in any real situation I would just look this up", but that didn't help). At the end, I had a bunch of pseudo-C++-code that should do it correctly.
I thought I was done, then the interviewer said she would go go copy my code and compile it after the interview to see if I was right, which blew my mind. It was never mentioned previously that the code would actually be compiled and run, and with no syntax highlighting or ability to compile and test the code myself there is zero chance it was ever going to work.
I never heard back, so I'm assuming my code failed and they left it at that. Anyway, I'm much happier now that I think I would have been at Google.
Their loss.
As soon as we settled on the problem to be solved, I ran to my nearest copy of Knuth's _Seminumerical Algorithms_ (having copies of Knuth's three volumes both at home and at work has been well worth the investment). Because I had studied the book carefully a decade earlier, I vaguely recalled that it contained several algorithms for problems like this. After spending a few minutes considering several possible designs that we'll study shortly, I realized that Algorithm S in Knuth's Section 3.4.2 was the ideal solution to my problem.
If Bentley needed to go look up an algorithm that he vaguely recalled studying in the past, just how awful of programmers are the rest of us that look things up, really?
That was the entire phone screen, and they failed me. This still burns me years later because it was such an obvious communication failure on their part - if you're one of the rare interviews that actually require me to write working code, you better be darn sure to mention that upfront, rather than 5 minutes before the end of the hour! - and yet I was the one who failed.
And yet somehow interviewers think that this will give them a good picture of how you'd do work on the job. Baffling.
But yes, this is asinine. Sharing your desktop through a video conferencing program and using the IDE of your choice would be far more realistic test, but Google likes to put hoops up to jump through that are smaller than your body.
Why can't you contort yourself like an octopus!? Fail!
I don't get how my interviewer (an engineer), didn't see the problem with it. I know that Google wants to use their own products, but that can't possibly be the norm for other Google interviews.
I just said, that can be solved with a topological sort, and then we moved on.
But I failed with another interviewer. He kept asking how to prevent hashing from producing collisions. The answer was universal hashing, but I had forgotten about that
I'm interviewing engineers frequently and although I agree that the question asked by GP is maybe not the best it still gives the signal if someone is willing to power through a problem with minimal guidance and/or ambiguous constraints. Something I'm willing to find out at the peril of pissing off a few candidates.
Software engineers aren't mathematicians. We don't invent algorithms or data-structures. That's not our trade-skill. And even actual mathematicians don't sit down to solve a real-world problem that no maths they're aware of directly solve—and then produce novel maths, and then use them to solve the problem—the very same year, let alone the same hour.
What I can do, as a software engineer, is to take algorithms that exist, and repurpose them or glue them together in novel ways that the designers of those algorithms never thought of, to do something new. Bitcoin, for one example, is a feat of pure software-engineering: it takes four or five existing well-known algorithms, and puts them together in a novel combination to solve a problem. I could maybe invent Bitcoin. But I can't invent Floyd-Warshall, if I don't know about it.
Google doesn't employ computer scientists (i.e. mathematicians who invent algorithms.) Alphabet does, under DeepMind and Waymo; but Google itself only employs—and only needs—software engineers.
Asking a software engineer, under pressure, to derive a novel algorithm, is a bit like asking a chemist, under pressure, to derive a novel class of chemical reaction; or a materials scientist, under pressure, to derive a novel material.
That's not the type of pressure that a real-world person in these jobs will ever be under. And moreover, it's precisely the type of pressure that people with experience in these positions have learned to mentally associate with "going in the wrong direction, toward wasted effort", flinch away from, and to turn around and study the literature instead.
It's ironic that Google expects its employees to all have university degrees. If there's one skill people who've gone to university are guaranteed to know (and to have built up a reliance on), it's consulting the literature.
Open-mindedness goes a long way. Also typically our interview questions are set up in a way where it's expected you won't finish but try, which reveals a lot about personality and how problems are attacked.
This attitude will keep you from hiring someone who will just "do the right thing," which is to look up stuff that can be looked up, and also persevere when an off-the-shelf solution won't be sufficient. Plenty of engineers will spend time trying to reinvent the wheel when it is totally unncesssary.
He left eventually but person was hard to work with because you had to beat back this kind of shenanigans every step of the way.
It's much more efficient to remember the general shape of problems, to remember where you can find further information (books, chapters, etc). Remembering that something is a well-studied problem, and where to find a solution, is straight-up more efficient than remembering that solution.
Dijkstra once remarked that trying to make a computer act like a human brain was far less interesting than seeing what the limits are of a computer as something that is unlike a human brain. It seems the reverse observation is also true - human brains, once freed from rote memorization and computation (that's literally what programming does to us), can tackle much larger, more interesting, and more complex problems.
I'm glad that the interviewer read my resume closely to learn my alma mater, but not closely enough to realize I had a biology degree from it.
I tried again a year later and got luckier with my allocation of interviewers. I never did end up using any algorithms there.
I once had an interview where, for a pretty long question, one trivial step was to check that one set was a subset of another set. Neither set had any special preconditions, just two plain unordered Java HashSets. Not thinking twice about it, I wrote a simple for loop that checked if every element in the smaller set was present in the bigger set.
When I finished the question, the interviewer started questioning me about the runtime of the for loop. He started hinting that it could be more efficient, which confused me, since it seemed impossible to check every element of a set in faster than O(n) time. I also didn't see how it was useful to think so carefully about the runtime of such a trivial thing, seeing as the "story" of the problem indicated that the sets would never be particularly large and the task wasn't one that would be sensitive to a couple microseconds difference in runtime.
We spent about 20 minutes stuck on this, with me awkwardly repeating I didn't see how it was possible to be faster and him telling me to just think harder and look at the problem "mathematically", "forget about the code, just think, in math, if you have a set A and a set B, how do you efficiently find if one is a subset of the other?". Eventually we ran out of time for the interview. As we wrapped up, he revealed to me the elusive answer: "Since you're checking if it's a subset, you should use the built-in isSubset() method that Java sets have". Of course, he hadn't conveyed to me at all that he was looking for a specific built-in method, so I thought there was some secret algorithm that I would have to write to make it go faster. I didn't mention that though, and instead replied that even if it were a built-in method I didn't see how it could be faster than O(n) in its implementation. He didn't have response, and just stammered something like "well it's built in and it's actually the most efficient way" and the interview ended awkwardly. Anyways, I had my doubts, so when I got home I checked.
There is no isSubset() in Java sets.
There is a containsAll(). It's implemented as a while loop that runs in O(n) time, making it no more efficient than writing your own loop.
Naturally, the company ghosted me too.
The biggest portion of the in-house interview was some fairly simple algorithm puzzle involving solving some word game given some rules and a list of valid English words. That section of the interview ended with me explaining how hash table lookups are constant time and the interviewer insisting that they are linear time.
To be clear, there was no “gotcha” about collision resolution or anything subtle like that. My claim just came up as an obvious step in my explanation of the running time of my proposed solution and the interviewer jumped on it.
I thought I was quite cordial, but I didn’t back down, and the interviewer seemed quite aggressive. The other interviewer in the room at the time seemed very uncomfortable with the fact that I would question something so basic, but didn’t intervene or express any “opinion” on the “debate.”
I was rejected due to insufficient experience. :)
Not to troll, but have you considered that you perhaps were not qualified for the job? There are people that can recite details of convex hull construction algorithms.
All you need to remember is that you sort points by angle from a fixed point on the convex hull, and you can easily work out the rest of the algorithm as well as the proof of correctness.
Not knowing it is a relevant signal that you did not seriously attempt to compete in computer science competitions during high school and college and did not otherwise have a burning desire to learn algorithms and data structures nor a specific interest in computational geometry. Whether it's in Google's interest to select for that of course is debatable.
I'd argue it does not. Computational geometry is a niche. It's not even a niche that's particularly relevant to most of Google's development operations.
In modern software development, knowing the detail of specific algorithms off the top of your head and being able to implement them unaided is, at best, a parlor trick. I doubt very much that it even correlates to one's effectiveness as a developer. Even for development tasks which involve algorithmic work -- which many don't! -- knowing that various algorithms exist, and what they're used for, is much more valuable than having memorized the details of how those algorithms are implemented.
E.g. if you know that convex hulls can be computed by sorting by angle and sweeping, then you might come up with the idea of sorting by angle and sweeping in problems that are unrelated to convex hulls (e.g. determining what is visible from a given point in an environment with obstacles).
In general, if you know a lot of those techniques and heuristics, you will be much more effective at problem solving in domains where these techniques apply.
It is relatively rare for this to be a big factor in routine software development, so that's probably something one should filter for only if interviewing for roles where you might need to design novel algorithms (which Google probably has more than the average company).
I received offers from several others, some never called back. Ended up turning all those down though, as I had an interview with someone who helped step through the few mistakes I made as a learning process during the interview. One particular question I remember was basically building front-end components with Javascript, and my example had a loop with a write call in it. He mentioned he would compile the markup in the loop, then write it after it was finished, and asked why that would be better or worse. Had to think on it for a minute, but came up with a trade-off between more memory usage but less DOM writes, resulting in faster rendering. Worked that into the next coding example too, since it was similar but more complex. After the interview, when they called to schedule a follow up interview before I even made it home, I realized he was more concerned about whether I would ask for help, learn, and not make the same mistakes again. Worked there, learned a ton, became a senior dev just few years out of college, now I manage a suite of products for my current company. I don't think I would have gotten that kind of opportunity had I not had that first manager and job, so I strive to emulate that in my interviews.
One of my favorite questions is something like "describe a crisis that occurred and the steps you took to resolve it," and give an example of one of my many stories of pushing bad code to production, having a server crash, etc, etc. I love the question because it involves no coding, no memorization, no regurgitating of info. Instead, it resolves around the person being a hero, which in my experience usually gets them relaxed, comfortable, and talking. You also learn a lot about their thought process: How did they first notice the issue? What was their process for triaging it? How did they debug it? If something involved in it was out of their wheelhouse did they go to someone else more experienced for help, or did they search for similar problems online to try and narrow it down? Did they delegate tasks if the workload was too high for them? Once it was fixed what was the procedure it went through for testing / verification? Did you monitor the issue afterwards to make sure it didn't come back? Once it was deployed, did you search for similar issues affecting your other systems? Did it ever come up again in new code and you were able to identify it before it was deployed?
Obviously not all of these will apply to everyone, but the open-endedness of the question means you can probe a bit here and there throughout their story and gain a ton of relevant insight. And most importantly, it answers the question of "when things get tough, can you keep a cool head and think critically?" I can teach code, data structures, algorithms, whatever, to anyone. But the difference between someone who is always trying to learn and grow, takes initiative, asks for help, etc, and someone who just wants to do the bare minimum is night and day.
Side benefit is this usually takes up several minutes of an interview so they can't be used on BS questions like the one you mentioned.
And for what? Anyone that works with Android only has to wonder where do those algorithm magicians land at Google.
They are extremely useful to filter out candidates that simply cannot program, and who won't be able to no matter how much mentoring time you 'invest' in them. I've heard about interviews for senior engineers that were totally derailed by a simple FizzBuzz. I like wordcount (the wc *nix command) as a warmup/screening question simply because either: The candidate comes up with an algorithm for it and test cases OR starts counting whitespace and derails the implementation with a cascade of if-else for every new test cases that breaks the previous implementation (I've seen if-else to check for the n cases I suggested...).
But honestly I feel there is so much cargo-culting for coding interview. Especially if you ask for compliable code of well known (as described by a textbook) algorithms you ultimately assess rote memorizations skills and not engineering.
Convex Hull doesn't sound so bad to be honest. If I was using this question I would expect someone to be able to come up with the gift wrapping algorithm with maybe a little bit of help. What, as an interviewer, would really want to see is if the candidate can come up with test cases and a way to test whether his solution is actually a convex hull and then try to break down the problem and come up with an algorithm. I sure wouldn't expect to be able to type what's on the board and for it to compile right away (it's a board, not an IDE!) but I expect the candidate to be able to walk me through the code and run it line by line through some test cases.
So the next question is, will interviewers explain the problem if you're unfamiliar and not "fail" you if you can explain how you'd approach a solution?
I liked the convex hull problem because it's easy to sketch in 2D and explain in case someone doesn't know what it is.
Sounds like a very effective way to filter out people who haven't taken algorithms courses recently and/or don't spend hours every week on algorithm puzzle contests or solving algorithm puzzles for "fun." They could probably save a lot of time by asking your graduation year and looking at your hackerrank score.
https://www.goodreads.com/quotes/24194-never-memorize-someth...
It's OK to ask people general questions (what's algorithmic complexity, what kind of algorithms and data structures they know about, what are the tradeofs, etc).
But expecting people to remember the exact steps of an algorithm they last used 10 years ago at university is just stupid. It's like asking engineers to remember the tensile strength of a material they could use once a decade. That's what the documentation is for. It will take 3 minutes to look it up when I need it (if I need it at all).
It's even more important to recognize when the solution found with google is subtly wrong.
+ fibbonacci
+ a sort
+ a linked list
I like having candidates write out these problems on paper because it shows that they know how to think about code. Fibbonacci allows us to see that they have basic recursion understanding, and basic iterative loop understanding. Linked lists shows us that they understand pointers. And a sort shows us that you can structure more complex code well.
If you truly want the job, you'll take 15 minutes the night before to remind yourself how all of these things work, none of them should be particularly foreign or confusing to an experienced programmer.
That covers the coding part of our interview. For the problem solving part of the interview, we may give you problems that require using heaps or skiplists or graph algorithms, but for this part of the interview we're happy to let you import imaginary libraries that do all the hard work.
I write on paper so infrequently that I actually find it pretty difficult to write more than a few words. I certainly wouldn't want to write something out longhand in an interview!
Edit: It seems to me it would be rather unfair of me to ask people to write out their thoughts in Org Mode in VS Code just because that's how I happen to like writing notes :-)
I did it once or twice when I was 8 years old and didn’t have a computer yet :)
Seriously though - how long ago was that - not recently I hope?
That's pretty neat.
I'm struggling to understand what you mean? This is a learning opportunity for me, if you wouldn't mind posting a code sample or elaborating further.
int fib(int n) {
if (n<=2)
return 1;
int fibNMinus2= 1;
int fibNMinus1 = 1;
int tmp;
for (int i=3; i<=n; i++) {
tmp = fibNMinus2+ fibNMinus1 ;
fibNMinus2 = fibNMinus1;
fibNMinus1 = tmp;
}
return fibNMinus1;
}
vs recursive solution which is pretty but slow (and will fail when you run out of stack) int fib(int n) {
if (i<=2)
return 1;
return fib(n-1)+fib(n-2);
} def fib(n):
if n =< 0:
return (0, 1)
else:
a, b = f(n-1)
return (b, a + b)
(I say it works better, because it has the same asymptotic runtime, but fails better: When numbers get large, your C version will run into undefined behaviour that can cause arbitrary problems. The Python version will just crash with a well-defined exception.A better language than Python can run this recursive version for arbitrarily big numbers.)
But yes, I should have written "naive recursive solution". There are many ways to fix it. It just wasn't what the question was about.
If you have a decent language and a good compiler / interpreter, then the recursion with function calls will have no overhead over iteration. (Basically, in Haskell or Scheme your recursion will be compiled into the same machine language sequence of straight-line code plus conditional jump as the iterative loop.)
But, agreed with everything else you wrote!
And I instinctively distrust Sufficiently Smart Compilers ;)
> I can't be sure without measuring, but I strongly suspect the overhead will be mostly in tuple packing/unpacking and GC.
I guess that's the same overhead as in this imperative version:
a, b = 0, 1
for _ in range(n):
a, b = b, a + bThe recursive Python version above didn't use tail calls. I don't think that a Haskell or Scheme compiler would compile the equivalent versions into a simple loop.
GHC is sometimes able to do some of those transformations.
> The recursive Python version above didn't use tail calls.
Just to be more pedantic: it did use tail calls, but the recursive calls weren't the tail calls.
I was talking about this code:
def fib(n):
if n =< 0:
return (0, 1)
else:
a, b = f(n-1)
return (b, a + b)
Not sure what you mean by tail calls here. I don't see Python-level tail calls. The interpreter will call C code for tuple packing, but those aren't in tail position with respect to the Python code either.Why wouldn't the tuple packing be in tail position in the Python code?
Looking at https://github.com/python/cpython/blob/master/Python/ceval.c, here is the code that needs to be executed after the tuple is constructed:
case TARGET(RETURN_VALUE): {
retval = POP();
assert(f->f_iblock == 0);
assert(EMPTY());
f->f_state = FRAME_RETURNED;
f->f_stackdepth = 0;
goto exiting;
}
// ...
exiting:
if (tstate->use_tracing) {
if (tstate->c_tracefunc) {
if (call_trace_protected(tstate->c_tracefunc, tstate->c_traceobj,
tstate, f, PyTrace_RETURN, retval)) {
Py_CLEAR(retval);
}
}
if (tstate->c_profilefunc) {
if (call_trace_protected(tstate->c_profilefunc, tstate->c_profileobj,
tstate, f, PyTrace_RETURN, retval)) {
Py_CLEAR(retval);
}
}
}
/* pop frame */
exit_eval_frame:
if (PyDTrace_FUNCTION_RETURN_ENABLED())
dtrace_function_return(f);
_Py_LeaveRecursiveCall(tstate);
tstate->frame = f->f_back;
return _Py_CheckFunctionResult(tstate, NULL, retval, __func__);
I guess you could duplicate all this code in a special "pack tuple and return from Python function" C function which you could then really tail call.Any specific implementation, and in this case cpython, could do arbitrary weird things after.
Thanks for looking up the code!
This is not true. The recursive code will not compile with zero overhead even in haskell or lisp.
fib :: int -> int
fib 0 = 1
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
The code above will add layers to the call stack and has a speed complexity of O(N) and memory complexity of O(N).To optimize in Haskell you need to deliberately restructure your code.
fib :: int -> int
fib n = let _fib 0 a b = a
_fib 1 a b = b
_fib n a b = fib (n - 1) b (a + b)
in _fib n 0 1
The above code will have O(N) speed complexity and constant memory in Haskell. In order for Haskell or any language with tail recursion optimization to work the recursive call must take up the entire return expression. In short the coder must deliberately make optimizations and write recursion in a way similar to the original iterative syntax in order for such tricks to work.Though GHC is sometimes able to do some simple transformations on its own. But not in this case.
For anyone trying this at home: I suggest calculating your additions modulo some constant, so that the numbers involved stay within a fixed size. (Otherwise, you either hit the limits of Int and weird things can happen, or when calculating with the arbitrary precision type Integer, your numbers themselves will grow linearly in space.)
Additionally you have a spelling error on line 5.
To be fair, while the asymptotic runtime may be the same, the C version is about 180 times faster.
Though if we allow programs like the C example that give wrong answers or have undefined behaviour, I can write an even faster version that takes no time at all.
def f(n):
if n<=2: return (1, 1)
else:
a, b = f(n-1)
return (b, a+b)
def fib(n):
return f(n)[1]There is a O(log(N)) solution involving matrix exponentiation though, if you really need to get the big numbers.
That's not the type of thing I would ever expect a candidate to know in an interview, just something fun I've run across.
(And you can also use recursion in the fastest implementations. You just wouldn't use the naive recursive solution.)
fib(n) = (((1 + sqrt(5)) / 2)^n - ((1 - sqrt(5)) / 2)^n) / sqrt(5)
I even understood, once, how to arrive at the magic numbers :)I remember that it's possible but I forgot all the required math :) Now that I googled it it's not THAT bad
https://medium.com/@andrew.chamberlain/the-linear-algebra-vi...
Of course the only use is to look smart once a decade when the subject comes up :)
Whether this is "fast" or not depends a lot on the concrete implementation of your arbitrary-precision real numbers.
As a nice thing, the second term (after the first minus sign) is smaller than 1, so you can omit it by rounding the result to the nearest integer; all the game happens in the first term.
If you can do arbitrary precision arithmetic (including powers and square roots) in unit time, this one is fastest.
In practice, this algorithm is not the fastest, because handling arbitrary precision floating point numbers is a pain.
Have a look at the matrix exponentiation algorithm for Fibonacci numbers in http://pages.cs.wisc.edu/~mhock/SSL/fibcalc.pdf
You can implement the matrix exponentiation via repeated squaring recursively even in a language like Python that doesn't do tail call optimization, and it will still be fast: your recursion only goes to a logarithmic depth.
In any case, recursion vs iteration is an implementation detail. Especially if your language supports tail call optimization. Have a look at this example:
f(0) := (0, 1)
f(n) := let (a, b) = f(n-1) in (b, a + b)
f is recursive function over tuples of integers. And f is basically equivalent to the typically iterative algorithm for computing Fibonacci numbers. fib = 1 : zipWith (+) (0 : fib) fibfib 1 = 1
fib n = fib (n-1) + fib (n-2)
At least for this part of the interview, I'm not worried about your problem solving skills I'm worried about your programming fundamentals. We'll test problem solving in a different session.
Is this really a useful exercise? Why not present them with an actual problem that is relevant to your field and see how they approach it?
These are considered pretty basic stuff that every programmer should know..
The explanation I've heard is that good devs generally get hired after only a handful of interviews, whereas really bad devs are going to do a lot more interviews on average before they get hired, so you get a pretty skewed sampling even if there aren't that many really bad candidates around.
We are in a bubble, if we read programming blogs and think about programming in our free time, we are definitely not the kind that FizzBuzz exists to filter out. But from the perspective of companies, it makes sense if they really understood pointers or recursion or graph manipulation, because there are so many people lying on their resumes, not having sufficient analytical skills despite doing some resume driven cargo cult development etc.. And as an industry we don't really have an alternative to these algorithm interviews at scale, at the point we rely on non technical HR people to filter out resumes for us and they literally grep for framework/language experience.
Second level is how they explain the simple recursion that’ll hit stack limits (i.e. without tail recursion)
Third level is using accumulator/tail recursion.
See how they can express these ideas and are they able to effectively communicate their intentions.
I'd still have you write the full thing out, but I'm guessing you'd do just fine.
Only when the interviewer finds someone “smarter” than himself does he approve of hiring the candidate.
It is an ego game.
Perhaps this describes OP.
The interview process for the job I have now was a massive breath of fresh air.
The application asked for code samples and a cv. It was a small company and the CEO, CTO and direct co-workers all drove the interview process. The process was entirely conversational. First an intro phone call with the CTO and then a questionnaire via email in which I answered about 30 questions on various topics that were all very practical daily software development type stuff. It was painless to respond to each with about a paragraph in detail. Then a call with a direct co-worker about the questionnaire and this was my opportunity to ask questions of him about the company. Before getting the interview they actually read my code samples and reviewed my Github account. In the interview there was a ton of discussion about the company, its culture and all the of the above discussions. Following this was compensation negotiation with the CEO.
Everything about the hiring process said to me yes this is the place, they get it!
Or
“You do not understand recursion nor Fibonacci”
FTFY
(defun fib (n &optional (a 0) (b 1))
(cond ((zerop n) a)
(t (fib (1- n) b (+ a b)))))
With tail recursion, that should be as fast as the iterative solution and uses as much memory to store the intermediate values.Of course, the Fibonacci series also grows incredibly fast, so practically speaking, unless your language supports arbitrarily large integers, you'll never generate even 100 elements of the series.
What are the practical applications of recursion though ? Other than sorting and DFS ( well even DFS can be done iteratively with stacks ). I'll be curious to know.
I find testing for HashTable/HashMap knowledge to be far more practical than testing for LinkedLists simply because you can't escape HashTables in today's world.
Traversing and transforming nested data structures.
Just last month I had to write code that maps flat data from one system into a nested structure required by another system.
We wrote mappings as map literals and the code traverses them creating a new instance of the map filling the leaves with data from the input row and running some business logic on it.
I'd also like to add that because of this I adapted the traditional whiteboarding exercise at my current company to be about problem solving and design, and not about how many data structures you've memorized.
When a candidate comes in, I give them a fake-yet-realistic product requirement (like count elements in a real-time stream from field sensors) and let them run with it however they see fit. I put zero restrictions on the tech side of things in order to let the candidate shine (hopefully) in whatever tech they are most comfortable with.
I make sure to ask for feedback on the exercise and I've gotten all positive feedback from candidates.
> I adapted the traditional whiteboarding exercise
Lots of engineer types freeze when they have to make a presentation. I remember a meeting early in my career with literally three people in a conference room and I almost had a panic attack. No white board. People I already knew. All I had to to do is explain my ideas to three people. I did improve. I've given many public talks sometimes to hundreds of people and today I like public speaking. But I'll never forget where I started and that the person I'm interviewing might be very nervous. Putting them up on a whiteboard and into presentation mode only amplifies that nervousness. Just talk to people. Get them into that flow that comes from talking about something familiar that they are excited about. For most people a whiteboard test is not exciting. But if you give me a paid take home coding exercise, that's exciting. I like code, and I like to get paid for it. So if you really think you need a test, consider a very high signal test that is the exact work they will be doing.
> I make sure to ask for feedback on the exercise and I've gotten all positive feedback from candidates.
In an unequal relationship like that you are going to get a lot of false positives. If I really needed a job my response would be "loved the exercise, looking forward to talking to you more and discussing next steps if I'm the right candidate".
That's definitely an unfortunate experience, but isn't giving presentations to explain your ideas - sometimes to people you don't really know - actually a significant part of the job? I'm an IC, and I present designs and project plans for feedback to groups of up to a couple dozen people, or to VPs, on a pretty regular basis. If I couldn't do that competently I would be failing at my job, because that kind of communication is just as important as actually writing the code. If I were conducting an interview and discovered that "public" speaking on the order of a few people in a conference room was extremely difficult for you, I'd probably consider that an important red flag.
> isn't giving presentations to explain your ideas - sometimes to people you don't really know - actually a significant part of the job?
For many engineering positions it is not. There are loads of shops where the developers, even senior developers, mostly just write code. I have hired many of them and put them to work successfully building stuff while I deal with the meetings.
> If I were conducting an interview and discovered that "public" speaking on the order of a few people in a conference room was extremely difficult for you
And yet I worked very successfully as a junior developer for a couple of years before I ever had to attend a meeting like that. Among the other 100 devs in the shop, I was considered a top talent at coding. That's not to brag but to point out that I was adding lots of value to the company without having to attend meetings with people from other departments. My manager did that. My manager did not code, although he could if he wanted to. In fact at that company they created a separate path for highly talented engineers who wanted to continue coding but wanted to avoid management and meetings. That was a couple of decades ago and less common, but I think it's a lot more common now.
And the fact that I can now publicly speak in front of hundreds of people should hopefully encourage you that it's something people can learn if they want to. Some people don't want to. There are roles for them too.
Believe op is using it as "individual contributor"
I've never heard of someone not liking the term "Individual Contributor" before
I always assumed the term just leaked out of the HR world and into the general parlance.
If you're in a place where an IC can potentially make half a million or million dollars a year and drive some very interesting project work and be highly respected, no.
If you're in a place where not making it into manager track puts a very low ceiling on earning potential and respect, then yes it can be condescending.
This varies a lot by country, industry, etc.
Individual Contributor, used to contrast with "Manager". Point being, my main job is to design systems and write code, but I still have to do some of the organizational stuff sometimes.
>There are loads of shops where the developers, even senior developers, mostly just write code.
Okay, so your experience is different from mine. I'm surprised that there are places where this is really not a meaningful job requirement, and I've never worked at one, but I believe you.
>it's something people can learn if they want to
Sure... but so is coding. Part of the point of an interview is to see what skills and traits you already have. If you're missing some, that can be balanced against the ones you do have - it's not a dealbreaker, but it is still a negative.
>Some people don't want to. There are roles for them too.
Again, not where I work. Engineering, even at relatively junior levels, includes collaboration and explaining your work. You can't just say you don't want to do that - or rather, you can, but you'll have no upward mobility and be managed out pretty quickly.
Is that something they’re going to do on the job? Very unlikely. So why are you not only testing for it but testing for it in a fake time-pressured stressful situation that also rarely exists on the job? (Yes , we all have deadlines but when are they ever 15 minutes on the spot?)
Perhaps you should have entered the education field where you could give such exams day after day to your heart’s content?
I've seen one place that wanted developers to do a full presentation with slides and all to a group of people.
The topic of the presentation was completely up to you, didn't even have to be a technical subject. You could do a presentation on baking if you wanted.
Was doing presentations a part of the job of the developer? No. They wouldn't have to do presentations in their day job...
I didn't go for the job and have never understood what they were looking for.
Then if it’s a front-end position we can move onto UI components for it; for back-end or full stack I focus on implement a couple of the CRUD operations.
You really get to see how people think and will work on the job with questions like this.
Implementing a sorting algorithm from scratch is a waste of time in many projects: use your libraries and get on with life. That’s why such interview questions are not important to me.
Interviewing is hard and I applaud you for trying something newer and more realistic but I'd be cautious in thinking "spend 30 minutes designing a system and be prepared to defend your work with massive risk/reward hanging in the balance. Begin... NOW!!!!" is representative of how someone will work on the job. There are an awful lot of people who will solve the crux problems driving home after the interview or the next morning in the shower vs. on-demand.
I certainly don’t say BEGIN NOW! It’s a conversation. I continually ask questions during the design and ask the candidate to speak about the decisions being made.
In all honesty this process can easily last more than 30 minutes.
This is not a hard problem for someone with the experience I want, and there are many different correct answers.
Personally I'm way too anxious in interview settings to produce decent code. In interviews I find myself trying to get everything right first time, but in reality that's not how I work. I prefer to develop iteratively and debug as I go.
I'm also quite a slow and deep thinker. It's not uncommon for me to think about a problem for a good 15-20 minutes before writing any code. In this case I guess you would have some time to prep the night before, but I'd still be very nervous about coding on the day.
I prefer home assignments and that's typically what I'll do when interviewing people. I like to keep it simple and open ended. Simple because I don't want to waste their time and open ended to allow them some room for creativity because often we don't have explicit requirements in the real world. This has always worked quite well.
I've never been a big fan of giving code interviews, however when I have to give them, I'm far more interested in the candidate's thought process around how they understand the problem and what needs to be considered in building the solution.
I will say that one of the best "interviews" I've had included a portion where I worked with one of their engineers on a design problem they were actually having. It felt very collaborative, which allowed me to relax a bit, and I think we came up with a pretty good solution. I didn't mind doing "free work," because for me, it's fun to solve problems like these.
I've been around the block a few times and I LOVE system design interviews, both as an interviewer and interviewee. They are much more collaborative and "fun" for me. The good news is that I've been managing for several years at this point, so those types of interviews are far more prevalent than coding.
Also they'll try to claim copyright on your work (with pay) and reject you outright.
Agreed. The best jobs I've taken had interviews like this, or paid assignments.
The best way I know would be to work with someone for a week or two on a real problem, but that's way too expensive to trial a junior role.
At least for us, the system is more optimized around avoiding false positives than ensuring we don't pass over someone good.
Since the denial rate in our industry is so high, you can see which one is more preferable.
So if I get the job will we just touch base ever week or so? This sounds unlikely. Why can't you break work down to the point that you can pay me for 3-4 hours of real output and then use that to evaluate my quality?
All these tests around recursion and linked lists, etc are a feel-good proxy for actually measuring suitability, If someone is actually implementing them (IF!) it's not the junior, new-person; it's the senior architect who does it once every few years in a shared library. I can count the number of times I've used recursion in (a) a non-toy implementation and (b) not ripped it out and replaced with a faster, clearer iterative implementation on one hand.
where have you been all my life? ;)
I'm an autodidact, zero formal bg in comp sci. I suck at timed tests and algo interviews. Fifteen years I've been at this and I've worked with several 'full stack' teams, none of which had a single engineer who was within a thousand miles of what I could do with CSS (and they're mostly utter slobs wrt HTML). And as to the endless javascript demands, I will never be of interest to google (and the feeling's mutual) but I always get the job done, and often the job is something FE that none of my esteemed colleagues would know the first thing about how to achieve, comp sci degrees and recursion expertise notwithstanding ... not to mention that every one of them has as many stack overflow tabs open as me.
I'll get back to my sorry little js projects now, maybe I'll get another job before I grow old and die ;)
Your question topics are completely useless to normal software engineering work. And this proves how immature your company is, in understanding the nature of the work.
Perhaps you should consider asking them instead, what their technique is to ensure reliability, throughout, and redundancy in their code? Can they make their code self-heal itself? Or to make some minor decisions to restart itself, if optimal conditions are not met.
You know.. basic software engineering stuff.
>"because it shows that they know how to think about code"
means nothing at worst, and at best indicates you'll only be happy to work with people who are replicas of yourself.
Take home is the way to go, unless the position is some sort of public exhibitionist analogue developer position.
The least I think you can do is move from paper to machine, and inform them they should bring their own machine, or offer them use of one with many envs preconfigured.
Ideally the interviewer shouldn't be concerned about absolute code correctness, such as syntax or argument position, and should be interested more in how you're able to solve the problem, which should be a novel, yet simple task that doesn't require studying up on 200 level algorithms.
You want to hire developers (for permanent full time roles, at least) who have a good conceptual grasp of programming and logic, rather than their particular knowledge of a language or framework, or their ability to search on stackoverflow and run their code through a linter.
The worst interview problem I've been given was to write an AngularJS directive, I think literally to simply take an attribute and display it. I can't remember at the best of times the syntactical oddities of AngularJS, let alone when writing with pen and paper in an interview with no resources.
One of the better problems I was given was around parsing XML, from memory validating that opening tags matched closing tags, while allowing for self-closing tagsI remember the problem specifically didn't include any more complex facets of XML. Another was to reverse a string in-place ("hello world" -> "dlrow olleh"), and then to modify the algorithm to reverse the words but keep them in place ("hello world" -> "olleh dlrow"). Obviously in the real world you'd just use built in methods, but it's a problem that should be solvable without digging up your old lecture notes.
I've always felt comfortable writing code (or at least psuedocode) with a pen, but I think it's unfair to require a candidate to solve the problem on paper or whiteboard if they feel more comfortable typing on a computer instead, all that achieves is disadvantaging otherwise capable candidates who for one reason or another can't write code with a pen and paper. As long as they aren't googling "how to reverse a string in place", it immaterial what writing tool they use. If they feel more comfortable using a brush and papyrus, or carving a runestone, then that should be perfectly acceptable too (provided they bring their own writing material).
* linked lists shouldn't be used anyway. and if they are used, you should use the standard implementation
* directly applying fibbonacci is trivial.
* sort: This is just a memorisation task, what's the point? (99% of the time, you shouldn't implement your own sort)
although, I agree with the open-book approach in the problem solving part.
Used recursion only once. Once.
(but that specific time recursion was really a life saver)
When programming in Clojure I use recursion a LOT.
I see no reason to use recursion when asked to calculate Fibonacci numbers. A loop looks like a more reasonable choice that also avoids typical pitfalls associated with recursion. Maybe that's because I did embedded programming for a while.
I suspect recursion is introduced in CS classes with this example, but people understand it as "you are supposed to use recursion to calculate Fibonacci numbers".
Beauty is in the eye of the beholder, but a loop is hard to beat as far as simplicity goes, and you don't depend on your compiler being clever enough to optimize tail recursion.
If you need to traverse a tree then sure, but with Fibonacci you don't even need the stack to begin with. You only need to keep a previous number.
But, you are not seeing how people think about code. You are seeing presentation prepared before hand. That whole part abour seeing how people think, as much as it is repeated, is nonsense, so maybe it is not much of loss.
In school I played with sorting algorithms, in business if I ever found a developer manually writing a sorting algorithm, I would consider them inept (unless there were very specific reasons to do so).
If someone didn’t know how to sort a list using the built in or standard library of whatever language they are using, I would know very quickly that they have almost no experience writing anything useful.
When was the last time you wrote a sorting algorithm?
Acceptable answers:
- You mean sorting a list? - In school - Why would I write a sorting algorithm? - Never - (Glazing eyes and other body language that indicates frustration)
Red Flags:
- Anything that indicates they think writing a sorting algorithm is a perfectly logical thing to do during the course of software development.
(Note: The problem is sorting may seem like a well-understood problem, but it’s actually not. Only a person who studied the algorithms in school as an assignment would feel comfortable with that code.)
I think the ability to come up with relevant and important questions to ask about the task given is more crucial than whether they can solve it. You can look up answers to questions from hundreds of good sources, but you need to be able to generate the right questions that need to be answered first.
Completely agree with this statement.
I would add that having the proper vocabulary is an important part of generating the right questions.
As a programmer, your task is to find algorithms to solve problems. Sure, sorting numbers is a solved problem and in real life you should use a library. But you will not find a library for each problem you encounter, and sorting is a very simple problem to solve compared to anything you'll find in real life.
Still, even using a pre-learned algorithm demonstrates some level of confort with algorithms in general, and can be used as a stepping stone during the interview to shift the problem slightly to see how they adapt the algorithm.
For example, if a candidate is clearly taking their time and essentially working out the algorithm themselves, and succeeding, that demonstrates the skill and we can move to other problems. If the candidate just breezes through and finishes in 2 minutes, then we can change the problem ad-hoc to try to get them off the beaten track a bit (say, if they wrote quicksort, maybe ask about making it stable, or sorting even numbers differently from odd numbers, off the top of my head).
Trivia does not provide evidence of skill, it demonstrates prior knowledge.
It would be better to introduce a unique situation that would place everyone at the same starting point.
Even so, knowing very widely talked about programming trivia is still a signal for interest in the art. I'm not sure that sorting algorithms are a good example of what I'm thinking, but I always award extra mental points to candidates who seem knowledgeable about the field (e.g. they know the general consensus on manual memory management vs garbage collection). Still, I wouldn't consider these sorts of things dealbreakers by any stretch of the imagination.
In a weird way though, I’ve at least grown to understand why it’s so popular, and I don’t think it’s just because FAANGS do it (though I think that’s how it came to prominence). It boils down to showing as an engineer your capable of being flexible and malleable your change and understanding. Some places definitely do this better than others, and I think it says a lot about company culture if they are Adversarial about it or not. In my experience rather unfortunately even good places to work can be adversarial about it.
The massive downside is and always will be it puts so much onerous on the candidate because you don’t really know what they are going to ask and freezing up or getting stumped is very frowned upon in these style interviews from what I experienced.
My tip to anyone though is just to practice, but I’ve yet to encounter places that don’t employ some technique to test algorithmic thinking and understanding of complex systems in some way.
...because you like working through problems on paper, and your interview process is designed to find people like you.
Kudos for letting candidates know what’s going to happen, it’s just that when I see problems that are clearly just a stand in for “do you know X?” I always wonder why interviewers don’t cut to the chase and just ask directly. “Are you comfortable with recursion? Can you describe it? When does it tend to be applicable?”
You learn it quickly when teachers do oral exams at university :)
Code doesn't lie, so I understand why people like to check candidates that way instead of relying on talk alone. I would just prefer if it wasn't a hit-or-miss test on what algorithms you memorized.
I'm doing leetcode now, as a senior engineer there is no way to get a decent job without being tested like a college fresh-out as far as programmer positions are concerned, no complains, I will do them, it is the market picks me, not the other way around.
To me even though this is painful, but at least it is "merit-based", what I dislike the most is that you got a job based on other factors instead of how able you are.
1. Dijkstra's 2. Kadane's 3. Bellman ford - negative edges
Just using a graph was the highlight of that month for me. (The data wasn't already in a graph.) Reading the wiki, it may have been Dijkstra that I used under the hood. (I just wanted the sum of simple paths for all leaves to the root, for each leaf.)
Cheers for us.
1. Tree/graph traversal (certificate validation and a couple other random places)
2. Using, not implementing, hash tables
3. Generators/iterators/streams: minimizing the number of unnecessary list traversals or allocations made when you have to shovel data around
4. Circular buffers: specifically in low latency, high throughput applications
5. Some exotic string search algorithms in a very specific, highly performance sensitive inner loop
6. Database query performance tuning
7. Every now and then something vaguely reminiscent of dynamic programming comes up, but it's never an actual dynamic programming problem, it's just a "cache results of expensive operations" problem.
For my job you need something exotic once in a blue moon, and when that happens you Google for someone else's research. You're not making up algorithms on your own. If you want to test that someone can handle algorithm-heavy situations like case #5, you should be testing their paper reading and ability to implement that paper, not their ability to solve an algorithms puzzle.
Also relevant to my job: if you find yourself implementing cryptographic algorithms, you're almost certainly doing it wrong. You shouldn't be implementing cryptographic algorithms. When I need them, my job is to vet and correctly use an expert implementation.
The interview process is totally broken, as it tests mainly how much someone is willing to prepare for the interview, which might actually show more how little they focus on doing more productive things in their current job, at university or by starting interesting projects. It also scares away people who might actually be better at the job but not as good or interested in interviews - at least this was my experience at Google compared to the usually more interesting people I worked with at university.
It’s just more difficult to test beforehand how someone might actually solve a problem in a good way as you describe. If applicable it’s possible to look at prior work, if you have any other good ways I’d be very interested.
Edit: this is actually a good thread to get some ideas on improving interviews.
It seems to control decently well for people who have practiced for interviews, because they do the usual dance of asking some clarification questions, mocking the functions, and narrating their code, but many of them hit a wall five minutes in. It's not because their algorithm doesn't work. They're using the right algorithm. The problem is that they haven't thought through "ok what do you do with the data now that you've traversed the tree?" In my experience, for my job, that's usually the actual hard question. For example, if you're checking a JWT, are you validating it in a way that is hard to subvert? Are you taking any time to think about pathological data inputs?
The counterpoint would be "what about a candidate who has solid coding skills but stumbles on the problem space because they're unfamiliar with it?" In my sample size of approximately n=10 since I started interviewing candidates this way (admittedly a small sample, but it's the sample I have), I have yet to see someone who writes code well who neglects thinking through the characteristics of the data up front. That said, it's a real issue. Data is usually contextual, so you're at an advantage if you have experience in the corresponding problem domain, which is not something I'm measuring for in the coding exercise. While I try to pick topics that should be universal, I inevitably get surprised, so I offer three different topics based on the candidate's resume, and I give the candidate a choice.
The biggest weakness I've seen in my interview process (within the scope of what you can do with only one hour) is that it doesn't control for nervousness or people who just don't operate well under time pressure. Unfortunately that's an unavoidable consequence of the mandated form factor, so I have to try my best to help relax the candidate and then rely on my gut for how much nervousness or pressure affected the interviewee.
I think the key element is how you calibrate towards the candidate, bringing common sense into the process. This is something Google tried to cancel out to increase fairness, which failed in my experience.
Maybe another issue is setting the bar too high during the interview to improve the metric on retention, sometimes it might just not be the match that the interview appeared to have.
I usually try to work with people on something small to get a feeling for how well we work together before committing to larger projects, but at some point I’ll need to start hiring, so I’m very interested in this topic.
IMHO the #1 thing that most developers are missing is database query writing skills. There is a shocking amount of terribly inefficient SQL out there that is wasting everyone's time and money.
As far as rolling your own crypto goes, I think the advice should be “only try it at home and don’t ever use it in production even for yourself”.
The programme in question was running into performance problems, and a few smart people had already banged their head against a wall solving them.
After lots of experiments and different approaches, my solution was to remove most of the advanced data structures that were in the code.
In theory, they should have given us logarithmic runtime on some common operations, but the constant factors were too large. I proved (in the mathematical and the practical sense) that a brute force scheme combined with a careful randomization would dramatically improve real world performance with a fraction of the previous line count.
Despite me removing those interesting data structures, I still count it as a great application of my algorithms-and-data-structures knowledge: a big part of expertise is to be able to spot opportunities for simplification.
For example, Enzo Ferrari once said that the secret to better performance is more horsepower.
A variation on the sentiment I heard in a movie: "turbochargers are for wussies, real cars have cubic inches!"
The problem in the previous solution was that it took a while to keep the fancy datastructures updated. (It's a globally replicated distributed system..)
And because of caches, sorting can sometimes beat hashtables.
The number of algorithms that removed multiple complicated stateful steps with 'and we randomly select an element from the array' was mindblowing. As I work on more and more distributed systems I keep seeing opportunities for simplifications with randomness (with obvious drawbacks on occasion).
You can sometimes put all the randomness in one part of the algorithm, even. Like shuffling before a naive quicksort.
In practice that's often even easier to understand (and debug!) than algorithms that keep making random choices as they run.
Shuffling and sorting are two humble but powerful building blocks of many algorithms. Both distributed and sequential.
In the example of what I did at Goldman, the core of the problem was essentially a souped up multi-dimensional bin packing problem. The big insight was that the typical distribution of our input data, random assignments had a high enough chance of being good, so we didn't need to keep track of everything in k-d-trees.
(k-d-trees are also awesome. And I even implemented randomized k-d-treaps at first, before I hit on an even simpler solution.)
And https://en.wikipedia.org/wiki/Expected_linear_time_MST_algor... describes one of my favourite algorithms.
https://www.cs.au.dk/~gudmund/Documents/randompearlnotes.pdf is also interesting.
You can find a lot of good material just via Google, actually.
If you read the likes of The Art of Computer Programming for breakfast, you might like 'The Discrepancy Method - Randomness and Complexity' available at https://www.cs.princeton.edu/~chazelle/pubs/book.pdf But it's not for the faint of heart.
I second the recommendation of Probability and Computing by Mitzenmacher and Upfal. In addition to being much more mathematically self-contained, there is more focus on models and techniques that I imagine software engineers might actually use, e.g. hashing, load balancing.
In addition, Randomized Algorithms by Motwani and Raghavan is a fantastic book, and should be doable after completing Mitzenmacher and Upfal. It goes into further depth on techinques for designing randomized algorithms.
A bit orthogonal but still related to the idea of "what should a software engineer read for interesting algorithm ideas", I really like Approximation Algorithms by Shmoys and Williamson. There is some intersection with randomized algorithms there too.
I was just giving the recommendations in the context of 'Do you know any good books or resources to read up more on random algorithms?'. Not with any regard to practicality.
I have to admit, I only managed to work through some of the chapters in the books I recommended. And for example, the main reason I know of Chazelle's book it's because it is available for free online and stumbled across it a while ago.
Btw, you seem knowledgeable. I have an algorithmic puzzle that has plagued me for some years now:
Starting with an empty heap, and a sequence of inserts and min-pops, can you compute what elements will be left in the heap at the end in linear (expected) time?
Obviously, you can't just run the instructions, that would take O(n log n) time.
I have an algorithm to verify a proposed solution in linear time. But I don't have anything solid for finding one in linear time. I have a hunch that soft-heaps might be useful. And there's probably an even simpler probabilistic approach.
Ideally, I'd like the solution in the comparison model, but if you have something that works on numbers only, that's also fine.
Fair enough! I still think it's a good recommendation, I was also adding on some thoughts on things that might be easier to digest :-)
> Chazelle also came up with the ingenious soft heaps.
Yes, soft heaps are very cool!
> I have an algorithmic puzzle..
Cool puzzle! Hmm, the solutions depend on exactly what you're asking.
The puzzle is substantially easier if the min-pop operation is not required to return anything. In this case, you are solving the much easier problem "return the top k elements of an array in unsorted order". You can insert into an unordered list and increment a counter every time min-pop is called. Then the last step can be done with a basic quickselect. See https://www.cs.cmu.edu/~avrim/451f11/lectures/lect0908.pdf page 21, the "QuickSelect" algorithm. You need to do some small modifications to give you the "top k" elements rather than just the "kth" element. This gives expected linear time, and the note describes a deterministic algorithm that makes this worst-case linear time. You can implement deterministic quick select using soft heaps, or instead you could also do a radix sort and then slice out the popped elements.
If the min-pop operation is required to return the popped element, then I believe you run into the sorting linear bound that prevents a deterministic O(n) solution. (Surprisingly, this indicates the hardness of the problem is not really in the last step, it's in implementing constant-time insert and pop). I can't think of an immediate solution off the top of my head, but I don't think a soft-heap provides the right guarantees here. I also don't know of a probabilistic data structure that provides both insert and min-pop in expected amortized constant time, and it seems that this could be an area of research. There are some better, but not quite linear results outside the comparison-based model (https://cs.stackexchange.com/questions/6455/an-efficient-dat...)
Min-pops and inserts will in generally be interleaved. The prototypical example has blocks of 2 inserts and 1 pop repeated n times. (All other interleaving patterns can be reduced to this one in linear time.)
QuickSelect doesn't work for this.
QuickSelect or Median-of-Medians approaches work if you only have a small constant number of interleaved blocks (of any arbitrary internal length). Like eg all the inserts first then all the min-pops is equivalent to finding the k smallest elements.
The main benefit of something like integer programming is that you get a clear separation of the specification of your solution and the algorithm that computes it.
When even smart people naively attack any kind of optimization (or selection) problem, the resulting approach often mixes the business logic for specifying the optimum solution and the code for finding that optimum.
That makes any change in business requirements very hard to implement.
The other points he mentions, beyond constant factors, are that algorithms with great theoretical characteristics tend to interact really poorly with gross real-world considerations like the memory hierarchy, and that worst-case performance is not average-case performance.
I'd say _some_ algorithms and data structures with great theoretical characteristics tend that way. Just as many other work great in practice as well. You have to measure and benchmark.
But being able to understand the core value of the algorithm enables you to adapt or modify slightly in order to get it to work as needed in the real world.
In general just knowing that there are specialized algorithms for certain classes of problems is 80% of the expertise you gain over years of experience. Knowing that things like Bloom filters exist when you hit a problem that could be solved by this class of algorithm gets you much further than expertly memorizing any specific implementation of the algorithm. There are a variety of them depending on the actual use case you are looking to solve for.
A person good at algorithms is some one who can make things happen with least effort possible. Not some one who can invert trees, even more so when there is not need to invert a tree.
You can see how good some one is at algorithm stuff to see how much drudgery exists in the way they do work themselves.
It's sometime best to use the 'worst' approach that allows most data to be as close to the CPU as possible for the longest.
- General IQ. Can this person understand and apply complex ideas
- Grit. Is this person hard-working enough to learn things that take time and effort
It's the software equivalent of the NFL scouting combine. The goal is not to create a test that is similar to the day-to-day job. But rather, create a test that isolates and evaluates a specific set of skills, which you think are important to the organization.
If I don't, I just stay put knowing I lucked out at a great company, knowing it would be hard to get lucky again.
Never attribute to malice that which is adequately explained by laziness and cargo-culting.
[1] https://www.businessinsider.com/average-employee-tenure-rete...
It's a proxy for interviewers to jerk their ego.
I do not see data and algorithm interviews as very specific technical problems.
I do not have a computer science background, and have been able to bring myself up to speed to the general level expected without too much hassle.
I don't think I'm particularly special. I just searched and spent some time learning this stuff over a few weekends. If you are serious about a career, I don't really think that this is too much of an ask.
Interviewers don't have choice here. Interviewers aren't free to come up with their own method.
So this is not a valid explanation.
Most companies require interviewers to pick a question from their internal 'question bank'
That's obviously not true....
> Most companies require interviewers to pick a question from their internal 'question bank'
Again, having worked at some fairly big and respected companies, this has never been the case.
I'm not interviewing for rote candidates. Everyone is different. Ergo, the questions are different. I could never imagine hiring senior developers and security engineers with questions from a "question bank".
If you're just doing boilerplate, you're probably getting very sub-par employees.
https://leetcode.com/discuss/interview-experience?currentPag...
Please take a look at these. I recently interviewed at FB and I got 2 questions in phone screen that were from leetcode with FB tag.
> Everyone is different. Ergo, the questions are different.
Facebook is running interview factory, they just don't have time to customize interview for each candidate. Their own recruiter told me to practise questions from leetcode tagged with facebook.
I agree with you re your reasons for not using a 'question bank' but thats just not the realty.
It can be both
From my experience, when you have a big pool of candidates, the ones that pass not necessarily super stars, but they tend to perform at a relative stable level.
Interview for the skills you actually need. If the person isn't implementing algorithms and data structures from scratch, it's a shit question. Why would you ask questions that don't match the actual work they'll be doing?
If they will be doing this work, then obviously it's a fair question.
See, black and white.
> Why would you ask questions that don't match the actual work they'll be doing?
As an interviewer, and likely peer or manager of the potential new hire, I want to understand growth potentials as well, so I want to challenge you during the interview. In my particular situation, there are so many candidates, and so many mediocre ones, we needed to raise the bar, and it served us well.
The "amazing scientist" maybe was not a good culture fit, or, yes, the interview was botched.
Good candidates are so good that they often enough compensate for bad interviews. Sure it means we sometimes don't hire the best, but that's better IME than sometimes hiring a not so good candiate.
https://medium.com/@gameweld/the-case-for-the-private-techni....
1) one or two people in the discussion (interviewers) already know the perfect solution to the problem and are contributing as little as possible to the discussion.
2) the actual amount of allotted time to brainstorm a solution to the problem is realistically only ~10 minutes not the ~45 minutes you are allotted because of the time it takes to implement the solution with real code.
It would be nice if no one in the interview knew the answer to the problem before starting the discussion and this discussion would be pretty realistic aside from the lack of help from the interviewers. However, you cannot easily/fairly compare candidates with so many different questions.
Technical interviews would also be far more realistic if they allotted more time for problem solving but I imagine if the standard 45 minutes was bumped to over an hour, the only outcome is that more candidates would perform very well and that's not an outcome companies actually want unfortunately.
My personal opinion is that all of this should be scrapped in favor of seeing what the person has produced and having them partially implement a solution of something they have written in the past. It is a virtual impossibility that anyone could work on a project of any sort without being able to sit down for an 8 hour interview where they are responsible for partially re-creating something they have worked on in the past. To this day I still remember large parts of source code I've worked on 10 years in the past.
Why would this be the case--at places where the number of candidates far exceed positions? This is the exception rather than the common case.
Even the very best tech companies are constantly filtering through thousands of people who claim to have worked on extremely complicated development projects but can't code extremely simple things.
* Youth. People who have very recently studied these things in school, and use the same languages as the interviewers, have an advantage.
* Free time. People who have families (for example) might have less free time to study "Cracking the Code Interview" and such.
* Absence of anxiety. This disadvantages women, minorities, and people with psychological conditions that should be covered by ADA. Also, people whose financial situation is precarious will be more anxious than those who don't need the job, independent of which is actually a better candidate.
* Conformity. People who can recognize the flaws in a measurement technique, and who have the strength of character to push back against its application - both good qualities for a candidate - will self select out.
There's a lot of overlap among these, of course. There are better ways to measure "general IQ" and "grit" (which are both questionable concepts anyway). I've passed every such interview I've ever taken, but I refuse to administer them (despite the fact that my refusal has carried a quite tangible cost) because whatever benefit they provide is outweighed by their many flaws.
I resemble some of those categories, and I don't know if I would feel comfortable making the leap to correlate them to a some inherent reduced level of resistance to anxiety. That seems like a generalization which I feel that, on an aggregate level, seems unsupportable by data.
I think that determination should be on a case-by-case basis, as is currently done at universities.
Is any of that even controversial enough to require citation? How many Psychology or Sociology 101 textbooks should I cite? It's easy enough for those who don't feel this kind of anxiety themselves to brush it off, but for those who are less fortunate all those magnifiers can create an anxiety level that's quite debilitating.
I'm sorry, excuse me? Are you saying that non-minority, non-women don't suffer anxiety? Your parent comment certainly seems to suggest that. Which, at a minimum, is flat out wrong. Educate yourself[0]. And then zoom out and ask yourself why it's not only permissible, but often lauded, to so flippantly say what you just said.
[0] - https://www.apa.org/about/policy/boys-men-practice-guideline...
To be fair, OP did say "That effect is magnified for anyone who is unlike their interviewers"
But, I do agree some evidence from OP would help their claims.
I wouldn't be surprised if minorities experience more anxiety, on average, in situations like an interview, though. I think it's established that imposter syndrome is more frequently encountered for example but it's too late here to go digging for evidence :)
No, and I doubt anyone would have read it that way in good faith.
And I'm not writing this as praise for your comment...
(Only this past week I had experiences that challenged my assumptions about certain demographics (seniors) and how I would expect they would behave, and how they actually behaved. The lesson I learned was -- don't assume, always collect real data)
The white-male interviewer power dynamic has some basis in reality (I've experienced it occasionally, not all the time), but its effect on my interview performance may be less than 10%? (to throw out a number). I find I'm much more affected -- maybe 90% -- about (1) my competence in the subject matter and (2) how well practiced I am (for instance, I know the theory for a great many subjects but am unpracticed at some of them, so I tend to stumble and lack ease when it comes to demonstrating my subject matter knowledge in real time).
For different people, those percentages shift, and I believe in a way that is not obviously or necessarily correlated with their demographic (psychological conditions, yes, but also depends on which ones -- some don't affect anxiety). But all I have is anecdata so I'm not able to provide strong evidence one way or another so this is just my two cents worth -- and I do mean this in good faith.
My basic point here is that even 1% would be too much. If an interview process creates any inherent disadvantage for some groups, I'd say it deserves serious scrutiny. BTW, by "inherent" I mean beyond what can be addressed by bias training and such. That can enable interviewers to conduct any type of interview in as fair and kind a way as possible, but not to change the interview structure itself. If the structure is the problem, training isn't the solution. I think the in-person white-board algorithm interview is unavoidably weighted toward factors that have nothing to do with likely on-the-job performance, and thus should be avoided.
Going back to whiteboarding: I don't like whiteboarding myself, but to be fair it does measure certain dimensions quickness-on-feet, memorization abilities, ability to exude presence, fluency in language, etc. While these are laudable abilities on their own, I agree they might not correlate with overall on-the-job performance (but it depends on the job).
I guess "job performance" is this amorphous latent variable y that is correlated with a bunch of direct predictors x which we can measure, u which we can't measure, so we use proxy variables z to stand-in for them: y = f(x, u, z).
The worry is that some candidates, who may be bad for the job, but just happen to be good at these proxy dimensions (or train for them) might get the job; on the flip side, we may exclude certain candidates who are potentially good for the job but perform badly at the proxy dimensions. Whiteboarding measures the proxy dimension z.
Edit: oh look, an article on HN's front page on this very issue:
I don't, any more. I'm at a company that enforces a very rigid structure that I don't agree with, so I simply opt out. I pay for it every review cycle. Ironically, the rigidity of that structure is explicitly intended to reduce personal bias, which is a laudable goal, and I believe it succeeds. Unfortunately, I think it just replaces personal bias with systemic bias.
When I did interview, which was a lot at times when I was in a leadership role at a couple of startups, my favorite interview technique was to let the candidate lead and I'd follow. If I wanted to ask about algorithms, I'd ask about one they'd used in a project they'd worked on. How did it work? What were its strengths and pitfalls? What others were considered? What bugs were found in its implementation, or caused by its use? Besides flipping the control dynamic of the interview, it often led to more interesting conversations. Highly recommend.
> what are some examples of better ways to measure general IQ and grit
IQ has been under a shadow since _The Bell Curve_ and I'm not keen on letting it back out. ;) If one must measure it, I'd say measure it directly with simple challenges (e.g. memory or pattern completion) or puzzles ... but even those are apparently fraught with cultural baggage and of questionable relevance to a knowledge-heavy domain like programming.
As for grit, it's often readily apparent from someone's resume. Were they self-taught, worked through college, or took a free ride? Did they stay with companies and projects through hard times and get promoted "in the field" or were they always the first rat to abandon ship? It usually only takes a few questions to figure out whether someone's a coaster or a fighter. Funnily enough, the people with the most actual evidence of grit are the ones least likely to have spent their time studying specifically for the interview. They were busy actually doing stuff.
In other words, I’d rather work with a disadvantaged person who may appear rough around the edges but made it this far and has the “general IQ” and “grit” to do well on the programming problem, than the preppy white kid who has a lifetime of experience preparing for the task of exuding status and competency when answering behavioral questions or engineering case studies, but lacks the “general IQ” and “grit” to solve the programming problem.
Isn’t the nfl scouting combine bullshit though? The players who tend to be most favoured are those who did well at playing football in the previous season, rather than those who scored well on the IQ or creative writing or jumping tests
After a grueling interview process at Goldman Sachs, with 7+ technical interviews that required me to solve very specific questions on college-level Maths, Stats and Computer Science (admittedly, I was applying for a quant job position), I was eventually asked to interview candidates myself. While I did not feel entitled to change the current interviewing culture at the company by asking questions of a completely different nature from what I got asked in the first place, I conducted my interviews in a very similar way to what you described. By no means did I expect applicants to reach a definitive answer, but I instead worked on the problems with them to see how far their intelligence, creativity, curiosity and, most importantly, their ability to well communicate their thought process would take them.
Such interviews used to take a while hour of my time (which is a lot to afford when you work in a bank), but by the end of each I believed to confidently ascertain the candidate’s ability to thrive on our team. In retrospect, it has served me really well.
All in all, the problems posed (and the solutions given to them) might not carry as much weight in the final decision as the discussion held with the applicants. As long as the questions asked give them some material to work on, and DS and algorithms usually serve this purpose very well for us engineers and developers in general, one should be able to effectively select candidates given some time investment.
I've used quite a lot of features from RDBMs, as well as topological sorting, LRU for caches, Unicode normalization, graph traversal, bloom filters, hash maps and so on.
I'm not payed to implement algorithms or data structures, but to solve problems. So for anything non-trivial I tend to use ready-made libraries.
I only implement stuff myself when it's faster and simpler to implement AND TEST it than to draw in another dependency, or if there isn't a well-made off-the-shelf component.
So what I've implemented myself at $work is pretty limited:
* depth-first tree traversal
* graph traversal
* parsers for various non-standard file formats
* maybe a topological sort once, not sure
Finally, many classical algorithms have lesser-known variants that optimize for some practical advantages (reduced memory usage, memory cache friendliness, sequential disk reads/writes etc.). So if I were to implement, say, a substring search, it might not be a by-the-book Boyer-Moore algorithm, but some subsequent paper that builds on it to add a few percent practical performance improvement.
There's not much point though in knowning the minutiae to the level that you can code one on the whiteboard without prior preparation -- which is probably the main point that the article relates to.
I use the STL daily. I know fairly well the complexity guarantees behind each data structure. That's one of the things I like about it versus other collections libraries. It forces you to be somewhat literate on data structures in order to make the right choices.
But no, I could not write you up a red-black tree from scratch without going away for a few days with my Knuth books and a few pots of coffee. Sorry.
It's just an exercise to see "how badly does this guy want it? how much did you cram?" Like hazing.
As an anecdotal story, I once interviewed at a well known HFT in Manhattan, after jumping through the phone screen and timed coding interview (involving four questions), you were invited on site. The first thing you do on-site (10 am in the morning) is take a 2 hour multiple choice exam consisting of 100 questions and get this - it was literally on scantron card, so they can score it right away (exactly how I used to multiple choice exams in high school).
If they didn't like your score, you were sent packing right away, otherwise the real interviews would begin with actual people throughout the afternoon. Allegedly, the way you knew this was, if you they asked you what you wanted to lunch, that meant you passed and could go to the one-on-one interviews.
I didn't get the job in the end, but I did get a ham sandwich and soda out of the deal.
Bootcamps don't help either, what you want is that "elite" education with a bootcamp price, possibly many bootcamps over time, as skill sets need to adapt and grow.
> Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
First, it's not remotely true that 90% of Google engineers use Homebrew, seeing as how almost all development is done on Linux (Max Howell is unjustifiably full of himself here). And secondly, he doesn't know why he wasn't hired, but it may well be because of the entitled attitude on display here rather than any coding shortcomings. No one wants to work with pompous rockstars. They may be fine for developing one-person projects out in the wild but they don't work well on team projects at large companies.
If you go into an interview with the attitude that the problems you're being asked to solve are beneath you and that you just flat-out deserve the job without having to prove yourself, your success rate is gonna be poor. To a big corporation, almost no one is as big of a deal as they might think they are, unless they hold a Turing Award or similar.
The expectation of a large engineering company is to hire someone who fits well into their way of doing things. Typically they want smart, humble team-players with predictable skills (AKA solid educational background and possibly industry experience).
However an open source tool author has completely different self-imposed requirements and capabilities. If successful, they have proven that they can ship reliable software, basically on their own, which people want to use. Which is great, exceptional even. But typically not in terms of the metrics of a large engineering company, except they actually do use the tool/library, deem it important and the role of the programmer would involve developing/supporting it.
This also poses the question of: "Why would open source author want to get hired by big company in the first place?"
Wouldn't this mismatch of expectations and skill-sets be a hindrance/waste?
Aren't there much better places for this exceptional open source author? Startups, other open source projects, self-employment/freelancing, SMEs etc.
I'd love to interview the creator of homebrew. There are so many dependency and reliabiltiy questions that it's clear brew doesn't handle well (same criticism of CPAN, and pip to some degree) in terms of performance or correctness that you could just talk for an hour about graph problems... who knows, something like... inverting a binary tree?
Someone told me they did all their development in the cloud and you aren't allowed to check out software locally? Does that mean they just use their macs as thin terminals? But what's running in the cloud for development then? Linux X desktops, or do you edit in a browser, or do you develop entirely in a console over SSH?
Nobody seems to talk about the developer experience at Google that I've seen, despite how much they talk about how they do operations and site reliability.
Many googlers work on the centralized google3 source tree where the source lives in the cloud and your workstation is mostly a frontend for editing a FUSE view (citc): https://cacm.acm.org/magazines/2016/7/204032-why-google-stor... among other documentation gives some details on the process.
Typically that work will be done on a workstation at your desktop. But if you want to work remotely, and you can't access citc from your laptop. So, you'd ssh into your workstation, or use Chrome Remote Desktop (personally, I ssh from a ChromeOS laptop to a glinux workstation with tmux). Others use CRD for a full remote desktop. At that point the dev experience is mostly what like other people experience, except that the source and build and test environments are in the cloud, rather than on your local machine.
That just describes one common case- devs and researchers writing stuff that runs on Google's internal resource management system, borg. There are many other teams, who have their own standards and approaches, which don't use the technology I described abvove. I'm sure there are plenty of devs at Google who actually build directly on their laptop, and commit code to open source repos without ever touching citc, or google3.
For me at least, the dev experience at Google feels like every other dev job I've had: ssh to a LINUX machine, write code, compile it, run tests, send it for review, submit. A lot of people who are C++ server developers and python client developers could drop into the Google environment and quickly be productive.
A lot of this is documented in external talks but it takes a ton of work to assemble all of it.
It's a running joke that $2k top-of-the-line Apple laptops are being used as remote desktop terminals when much cheaper hardware would be perfectly sufficient.
I wish it was slightly larger with better specs and more ports, only because I spend a lot of time in video chat and there isn't enough CPU oomph to do video chat and Google docs on an external display.
TBF, they do seem to have more than their share of great, but, not by a lot...
The problem was to divide a text into a number of tweets to make it a thread, with the obvious constraint that no tweet should have more than 280 characters, but you still wanted to minimize some cost based on how far your tweets were from 280 chars and where you divided them (e.g., dividing after a full stop is better than after a comma, which is better than between two works, which is way better than midword).
With a reasonable cost function, this really seems a textbook dynamic programming example (possibly much more credible than the entering-a-treasure-cave-with-a-rucksack story).
That immediately brings Tex box badness to my mind. And the related line wrapping algorithm: http://www.tug.org/TUGboat/tb21-3/tb68fine.pdf
Good spotting BTW, the line wrapping algorithm (where each tweet is a "line") is a perfect match for the post you are responding to.
When doing programming competitions, you're often trying to figure out what standard algorithm is similar to the problem and how you need to tweak it to match.
Eric's mit video on this : https://www.youtube.com/watch?v=ENyox7kNKeY
One of the things I miss about Usenet was that
nearly everyone read it with a fixed with font
so that if you choose your phrasing well so as
to make your text come out naturally perfectly
justified, it would come out that way for them
too.
English has so many synonyms and near-synonyms
for every word, and so much flexibility in the
ordering of words that you can write like this
in near real time.
You get to the end of a line, find that you're
just a little long or short, and you backtrack
just a couple words or so most of the time and
you can usually find a way that works. In this
paragraph, for instance, I was one too long in
the first line, but contracting "you are" down
to "you're" fixed it. I was short in that last
sentence, but inserting "down" fixed it.
Perfect justification by inserting extra space
is for amateurs.
Now we've got all fancy and use variable width
fonts and automatic wrapping and posting isn't
quite as fun anymore.
Give it a try. Use an editor with a fixed font
to compose your next post and try to get it to
come out perfectly justified without having to
insert extra spaces. When you paste it into HN
that will get lost, but the composing can be a
fun little English puzzle.On topic to the original post, I implemented Knuth-style line breaking in the Android text stack (working with Anish Athalye who was an intern at the time and did the first prototype). There were a bunch of nicely tuned implementations of advanced data structures and algorithms in there.
https://lobste.rs/s/n8tyip/data_structures_algorithms_i_actu...
I still say it is a bad interview question, but there were lots of interesting examples I learned about.
- GCC splitting IA-64 instructions
- Trellis quantization in lossy video encoding
- Knuth-Plass line breaking algorithm (mentioned here too)
- Some algorithms I knew about, but which can be considered dynamic programming (I'm not sure how interesting this is): A* search, Dijikstra's shortest path, Myers common subsequence algorithm, transitive closure algorithm
I would say the GCC one is most interesting because there's a link to the actual code and comments by the developer.
https://github.com/gcc-mirror/gcc/blob/master/gcc/config/ia6...
I think it could be one of those cases where if you had a more obvious representation you wouldn't need a clever algorithm, but there is probably some other reason (good or not) that instructions are represented that way
x86-64 (and most other architectures) can use multiple units at the same time using what's called a superscalar architecture. There's a hardware unit that figures out what units are in use and what instruction just arrived, and can either send the instruction to ALU0 if it's unused, or ALU1 if ALU0 is in use, etc.
But this hardware unit that does scheduling is complex, it takes up space that could be used by other stuff. IA64 aka Itanium, not to be confused with x86-64, is a VLIW (very long instruction word) architecture. The underlying assumption is that the compiler knows in advance what operations it's already emitted, and what operations are coming next, and the compiler can be considerably more complex than the hardware scheduler does. So a VLIW instruction isn't just "add eax,ebx" like x86, it's more like "ALU0: add r12,r48; ALU1: add r93,r42; SHIFT: r60,12; MEM: load r17,r32". (Itanium had 128 registers) The compiler had to do a bunch of stuff that modern CPUs do in hardware. I think it even had to deconflict instructions; like the compiler had to know that an addition takes 3 clock cycles or whatever, so if you used ALU0 on cycle 123772 and then tried to use ALU0 again on 123774 something bad would happen, but don't quote me on that.
So at some point the compiler is going to have a DAG of operations that need to get run in a block, and it needs to bundle up those individual operations into bundles of (I think) 4. Sounds dynamic programmy to me. At least I think that's what's going on.
It turns out that most code is pretty branchy, which means many lines of code will have multiple entry points. This invalidates the assumption that the compiler knows what operation it just executed. So in practice, VLIW architectures aren't able to achieve their theoretical performance, and superscalar architectures are better.
I think the problem is being expected to regurgitate* 1-2 hyperoptimal leetcode solutions in 45 minutes while suffering from heavy interview pressure.
*by regurgitate, you can't simply implement the optimal solution either even if you know it. You have to put on a show where it seems like you're arriving at and iterating towards the optimal solution, "explaining your thought processes". But you can't waste time iterating and going down suboptimal paths either because you only have 45 minutes or less. Hence why ideally you know the exact optimal solution beforehand, or at least know the tricks and patterns to quickly get to the optimal solution for the type of problem you are tackling.
Recruiters and official interview guides say that your "thought processes" matter a lot, but reports from in the field tend to imply that the #1 most important factor is that you get the optimal solution. If you can't, your "thought processes" are worth little, barring exceptional circumstances.
"These two guys spent 6 months thinking about this problem to come up with this algorithm. Now pretend like you can independently come up with an identical algorithm in 45 minutes."
Agree. Also "there is no hard requirement in completing both part of the exercise" is another lie.
I remember a stint in research, about data analytic non the less, where rarely anyone had a good grasp of SQL or any other way to persist data for that matter. It really puzzles me to this day.
Might be me finding most ORMs to be harmful if used without understanding of the underlying technologies.
See eg https://en.wikipedia.org/wiki/Persistent_data_structure and immediately notice the warning 'Not to be confused with persistent storage.'
But immutable data structures are always trivially persistent.
Mostly that they prepared for an algorithms question.
It may be a good filter for 3rd-wave do-as-you're told programmers who stay in their lanes, produce by the book expected code, and just consistently obediently build things.
They wan better cogs for the corporate software machine.
If people are asking me algo questions, the job probably isn't right for me because my answer is "it depends". Last time I took one I was thinking "there's like 4 answer to this, what the fuck do you want?" it might as well have been "I'm thinking of a color" ... they have something written down and called it the "right" answer.
I gave a parallelizable answer, they wanted single threaded. I gave a single threaded one, they wanted 2 passes. I gave them a 2 pass version, they wanted one that didn't use collections.deque, I mean it was nonsense. "Guess what's on my piece of paper!" Cool beans bro.
Some people would have given them that answer the first time, I'm sure of it. Not me though. Not during the interview, not during the day-to-day.
I don't know how. I really don't. I don't know the right answers, all I see are a bunch of possibilities. That's why I'm first-wave.
The writer of homebrew isn't what Google is looking for anymore. His time to get hired there closed around 15 years ago. After the revolutionaries comes the administrators, a far less interesting but necessary entourage.
The people like me have all already quit. I've actually got nothing to offer them.
Companies that could build and not maintain: Lotus, Digital Research, Palm, Netscape, MySpace, Digg, Blackberry, Ashton Tate, it's a different set of skills. Heck, you can even toss the French Jacobins in there
They all shot themselves in the foot, I know, that's the point. Not having their eye on the ball and instead looking over the horizon is what built the empire, but then the ball hit their nose
Some people can do both (gates, zuck, bezos), but once you're at the Apple/Microsoft stage, you need the second group.
If they can pass that hurdle, you can almost be certain they know how and when crack open an algorithms textbook or use Google-fu to apply the right algorithm to solve a given problem.
(Knowing which data structures to reach for is far more applicable than being able to apply algorithms from memory. The article is good evidence of that.)
Those people do exist. Really, they think it's a thrilling joyride. Hard to find, but they're real. I look for those and run the team tight and small.
Fabrice Bellard, Ted Nelson, Theo de Raadt, Patrick Volkerding, Richard Stallman, Larry Wall, these people aren't off working at stable ibm-like firms. It's a different kind of thing. Look at Nelson's fiery career crash when he worked at Autodesk. Look at Woz and Paul Allen walking away or Bushnell getting rid of Atari. This isn't the grab-and-dash modern unicorn stuff, these people saw it wasn't right for them. The company outgrew them.
They couldn't do the job. That's not where they fit.
Chefs make terrible bus boys and bus boys make terrible chefs.
That's the big important lesson: The Chef is incapable of being a bus boy.
It's not "too easy for her" and she's not "too smart for it". The chef can't consistently, reliably, and efficiently do the tasks. The hierarchy is illusory, it's all about fit.
Drucker explains this better than I ever could. He's a good read
The vast majority of algorithms I use are for parallelizing complex workloads, failure detection, and scoring systems. I usually DIY after I find the OTS ones unsatisfactory.
I'm not "smarter", they're general solutions but all I seem to have in life are specific problems so specific solutions perform better.
I was impressed by the fact that nobody ever tried to argue with them before.
Basically they were hiring for a Python position and I know that part of the test is the same for everyone. Yet they didn’t know about open addressing.
I think we can all agree someone can be a poor software engineer and not have any red flags.
This has been something I find myself musing over every now and then for a couple years now. As we begin to relax barriers of entry, how do we maintain that some people fail/lose?
I'm an engineer and I use loads of software. I bet you do too.
> some people fail / lose
This comes off as a condescending way of thinking about the hiring process. Even if the candidate is not qualified for the position I want to leave them feeling like I helped them a little in their career or at the very least in their interviewing skills and confidence. You can find a good fit for a role without leaving the other candidates feeling like they failed. And I think that starts to get to the crux of the problem at some companies : the process is meant to boost the ego of the interviewer. Almost every senior dev has a few stories about how the interviewer just wanted to feel superior. We can do far better than that.
> The hiring process you are proposing is looking to methodically search for all of the useful qualities in the candidate pool and determine how they can best be applied at the company.
That's not necessarily what I'm proposing. I often need find the first qualified candidate who can start contributing. Don't let perfect be the enemy of good.
One of the ways I accomplish cost effective hiring is to go through applications in the order they arrive and the first candidate who passes the interview gets the job. If I get 200 applications and I find a suitable candidate in the 1st interview, why would I waste my time and money doing the other 199 interviews?
I sometimes even use recruiters when my time is at a premium. And that raises another interesting question: how is it that so many recruiters who can't code have been able to send me top quality candidates so consistently? Which leads me right back to my first point in this thread: this article is an excellent example of why most companies should never ask about algorithms in an interview.
So why are firms that are hiring so obsessed with producing more and more arcane barriers to entry?
As I always comment when this topic comes up: this process makes some sense at Google (where I work) where the sheer number of applicants is massive and false-negatives are perfectly fine because the potential applicant pool is so large. But at smaller companies, who can't pay Google compensation and feed you gourmet food, blah blah blah? And where your job will be mainly writing some JavaScript to drive web pages? Really?
I work around embedded stuff and spend a lot of time in low-level code, and I _still_ don't get to spend a lot of time writing algorithm and data structure heavy code. I actually really enjoy doing that kind of work, but on my own time, at my desk, with my headphones on, and some books and resources to reference as I'm doing it. This is how engineering / authoring / writing is classically done, by the way. Calmly, often solitary, and with space to gather thoughts and do trial and error.
Why should I be selected or deselected based on my ability to perform this activity in front of people in a high pressure situation? Often someone 15 years younger than me, fresh out of a CS program, and with a pile of hubris that goes with that?
For what it's worth I'm self-educated, not a CS grad, but got into this because it's what I like to do and spent many years privately studying on my own to get here.
FWIW I just this morning turned down a potential job opportunity because this is the interview process they wanted.
One of the most memorable was when I had to build a graph from sql statements, parse the sql statements, determine the dependencies between the sql statements by traversing the syntax tree and ordering the graph based on the dependencies so sql statements on each level could be evaluated in parallel.
It was one of the most fun and interesting projects I've ever worked on, it took me a few days to come up with a Java implementation and after a few bugs I rewrote it in Scala. I think I ended up with some kind of DFS algorithm if I recall, I might give it a shot at implementing it from memory and putting it on github.
But the general understanding of algorithms and complexity did help even in CRUD apps. It gives the bricks to form mental model of the underlying system. I don't need to code a b-tree but I may need to tweak its params.
Some research gave me Levenshtein distance and from there I first used a naive perl implementation before finding that you could extend MySQL and found an example and implemented that.
Took me 1/2 a day to go from zero to working prototype
Indexes come up a bit. I've seen many junior engineers struggle when performance problems crop up over time. If they don't have a familiarity with data structures and algorithms their "fixes" never seem to work and they get frustrated. I enjoy taking the time to show them how indexes can speed up search and when they don't give you much benefit. At small companies getting off the ground I think it's less important to hire people for their algorithms/data-structures knowledge.
At companies where the teams are working on high-performance or large scale problems it's quite essential. Being able to shave down build times, as in the article, is a big deal. Knowing how to scale a large problem is a big deal when the quality of the service depends on it.
There are also some problems that require it. I'm building a key-value data store as one of my side projects and it definitely requires knowledge of data structures and algorithms. You can't even implement one efficiently without such knowledge!
So I guess it depends on how much your team actually works with these concepts. If your hiring process is keeping the bar high but all you do is schlep JSON from one bucket to another you're missing out on a lot of good candidates for no good reason. If you're building networking products or databases then yeah, keep the bar high.
But within reason. I agree with the OP -- the need for exotic structures and algorithms is so rare that it's not a terribly good indicator of anything to use them in an interview unless you're looking for researchers.
update: spelling.
Most coding problems can be broken apart and the individual components tackled one by one. But that has two problems. One, it doesn't stress-test the programmer. Two, the most beneficial changes to a codebase come from a high-level understanding of the system. Implementation might be segmented, but the more of the system you can simultaneously understand & manipulate in your head, the better placed you are to manipulate the architecture.
Complex algo questions force you to manipulate a fundamentally complex problem. You can break it apart in some ways, but in general you have to be able to think about the entire basic algorithm in your head. Reversing a binary tree? You have to be able to visualise the datastructure you're manipulating and figure out what changes you need to make before you start writing. It's a stress test, it tests horsepower.
Granted, you can game that system by doing practice questions which undermines it to an enormous degree but I'm not sure what else you can do to test that.
Also a number of times I haven't got an answer in an interview only for something to pop into my head ten minutes out of the door (or a far more elegant solution came to me). You might as well toss a coin and save me the hassle.
Some of the stuff I personally worked on was tries and nested tries for routing/cache purge, LRU & variants for the caching algorithm on a cache node, and I implemented consistent hashing for the distributed cache.
There were some algorithms stuff for load balancing, but I didn't work on that.
I know there was a few other things, but I can't remember them right now.
- Space partitioning such as octrees
- Finite-state machines
- Behaviour trees (I much prefer to state machines)
- Too many machine learning and deep learning algorithms to list
I have also had to come up with boutique solutions to a number of problems. Even though I have never failed to deliver a solution in the real world I doubt I would pass any sort of algorithm interview without significant study. I don't rote memorize things and only (quickly) learn what is relevant when it is required to solve a problem. Unfortunately I also do not know of any quick way to test for that sort of ability that would be suitable for an interview.
I have been tracking luthiers and it is fascinating how detailed and varied each builder is.. the likelihood that the instrument will sound good is well correlated to how much time the luthier puts into refining his process. I don’t understand the rational for not wanting to learn DS/Algos this is just one part of it, there is also the whole business/customer side of writing code. There is a difference between never getting a demanding customer who understands the difference between a good instrument and something glued together and not wanting to know how to do something more than glueing it together is appalling. As a coder if you want to learn DS/Algos and you do not find a job the values that maybe there is more to learn so that find a job that values it. It will be competitive and you can fail but it is not wasted.
In my experience at Amazon and Google we all referred to books and colleagues when working through algorithms.
I did many SWE interviews at Google. I came up with my own question that obviously required using data structures and algorithms, but probably not something the candidate had ever thought about. Most people had a good thought process which was 90% of the question; some people arrived at the answer I thought was correct. Sadly, nobody ever came up with a better answer than what I decided was best. I was kind of hoping they would ;)
The problem with Google's interview system is that everyone gets to come up with their own questions. Some are bad! Some interviewers are bad! It takes the Hiring Committee a few candidates to recognize this and give the interviewer feedback about what's bad. But, that's why the HC exists and that's why you have 4 or more in-person interviews. The uncalibrated first-time interviewer does not have full veto power over hiring you. It can make for an uncomfortable experience (when is meeting new people and writing code on a whiteboard ever comfortable?), but overall the process does find good engineers.
The end result of the process, which I really liked, was that people on the team you're joining assume competency and don't explain simple things to you that you already know. I remember a few discussions in my first weeks at Google that blew my mind; we were talking about idempotency, and nobody needed to explain what it was. Every time I've ever used that word it derailed the meeting completely, requiring a remedial CS 101 course to bring everyone else on the team up to speed about that concept. Everyone at Google knows what that is, so you don't have explain it. It was nice. (This came up again when there was a discussion about state machines. Again, everyone knew what a state machine was, and used them somewhat regularly, so what was in my past life a discussion-derailing tangent was just a thing everyone knew.)
I'm not sure how people in the comments are saying that the "advanced stuff is never used", when the author used the A* search algorithm at work! I'm especially fond of this passage:
> You should also know about basic data structures that are pretty common, like hashtables, queues, or stacks. But specific algorithms like Dijkstra or A* are not ones you'd need to memorize: you'll have a reference for this, just like I had when implementing crypto.
Everyone complains about the lack of applications for these interviews, but there's not really an expectation to go beyond the fundamentals.
I think having a rough understanding of what's out there does help though. Just reading some books about them, kinda scanning over them thinking hmm that's interesting. And then when you need one you'll remember "wait I think some sort of x algorithm I read about might be able to solve this".
Greedy alogrithms are simple to come up with in an interview, Yes. But they are often wrong and even if they are right there is no way to know that, unless you construct a mathematical proof.
I would highly advice not using greedy in an interview since coming up with a solid proof in 15 mins is not really possible in all but simple cases.
a) A really good problem solver
b) Someone who has ran through all the example interview problems on leetcode or something similar
Then I thought that this might be similar to the Turing test. Once you’re that good at faking it that you can convince someone else - maybe the difference doesn’t matter at that point.
I just don't think it makes sense to test people on this kind of questions and then make them write CRUD all day.
Of course, there are positions where this kind of skill is unnecessary and I cannot know everything about the false negatives. But failure in these areas also correlate with poor coding skills, at least in my experience of a free hundred interviews.
That said, the only algorithm that I'm convinced that every single programmer needs to know by heart is state machines. Because using them can often save you a lot of code and complexity. And because you really have to know them well to recognize spots where they would be useful. And because using an off-the-shelf library to implement them is, for most use cases, more complicated, more time-consuming to implement, and less readable than a little light hard-coding.
Sounds like a terrible case of NIH. Why (re)implement AES when you've got battle tested implementations from OpenSSL, NaCL and practically any OS provided crypto APIs?
That makes sense. I would expect one to implement data structures and algorithms in a new operating system / kernel without the presence of any libraries available, except for libc, so that they can be reused or abstracted elsewhere in the kernel, drivers etc.
> There were cases where we had to build our own encryption / decryption implementations, formally verifying and auditing them, in the absence of the framework supporting it, or audited libraries being available.
I would leave implementing cryptographic protocols to the professional cryptographers.
But overall, I agree with the author to ask about data structures and algorithms that are actually used in the company if I were interviewing a candidate. It gives an honest account of the engineering decisions and reasons made in the team as to how implementing this DS & A helped them solved their problem and to test if the candidate understands these concepts.
However, after asking the candidate to implement a DS or A, if the candidate questions the technical interviewer if they use it in the company / teams and the answer is no, then it seems rather than a dishonest ego trip on the interviewer's side to test the candidate if they know the secret konami code.
I'm surprised this wasn't listed first. I always ask a question or two related to hash tables when I interview candidates and I'm continuously shocked that a good chunk of candidates don't know the basics of hash tables. I expect you to know that looking up whether an item exists in a hash table is _generally_ fast in practice, even if you don't know the specifics of O(1) best case, O(n) worst case. I expect you to know that it doesn't allow duplicate keys. I don't expect you to implement a hash data structure from scratch, but I do expect you to know which data structure implements a hash table in your language of choice (e.g. Object, Dictionary, Map, etc.).
It's the one slightly more complex "data structure" that I use all the time, so it's surprising to me when people don't know the basics.
The only other exotic data structure I've had to use is the union-find data structure. It's a pretty slick data structure, both because it's so easy that you could probably come up with the optimal one just by thinking about it for a few hours, but also because its runtime is O(n * inverse Ackermann(n)), the latter function grows so slowly that it is less than 4 for the number of atoms in the universe. Although, unfortunately, the data structure doesn't do a good job of telling you which union call is the one that merged two sets that should be separate together.
These are both good books that I actually like! They aren't quite as massive or comprehensive as CLRS but are easier to read as a textbook. I also like Steven Skiena's course videos. But I agree completely that they are unlikely to be something you'll use day-to-day unless you work as an algorithms specialist.
> Grokking Algorithms by Aditya Bhargava... I am convinced that you don't need to know more about algorithms than this book covers.
This is a nice and compact book, and I think he's right for most jobs that involve writing software. Won't be enough to get you past the idiotic algorithm puzzle interviews though. ;-(
What people seem to want is big-data or various tech stacks. I look forward to the time I can put even a bloom filter to work.
(edit: typo)
Still, that was a hobby project, I've never had to implement anything similar at my regular job.
It's probable that I've done some of the other stuff -- graph traversal comes to mind as feeling like something I've done professionally -- I feel like I've done stuff like that maybe once or twice in ~20 years. While it was useful to have that knowledge, probably, it wasn't even remotely representative of regular work on those jobs.
But that raises another question: is it still worthwhile to test for something you'll use 0.1% of the time on the job? Like, say I didn't know anything about graph traversal, and came across a problem that (even though I didn't know it) was perfectly suited to a solution involving a well-known algorithm. I might search around a bit, but ultimately my solution will probably be pretty non-optimal, might involve brute-forcing, and might be difficult to understand and read since I had no idea what I was doing.
On one hand you could say yes, that's important: even if you will barely use this information, it will be absolutely critical that you have it already and understand it when you do run into a problem that needs it, to the point that we don't want to hire you if you don't have it. On the other hand, you could say that picking it up as you go along is fine, or even writing a bad, brute-forced solution is fine, and the likelihood is that someone else on the team would notice during design or review and suggest the correct approach. You could even say that even if that doesn't happen, a bad implementation of part of your stack isn't even that big a deal; we all write so much technical debt for various reasons, this is just another thing that someone might have to revisit and improve later.
I'm not sure where I fall on this, really.
No need to sort everything again after adding 1 element.
Considering Skype is at best laughable compared to other IM applications, I'd not boast about working on it. I used Skype over 10 years and after it got bought by Microsoft it gradually started to be worse and worse, to the point I had to look at other IM in order to communicate with my clients.
I have a question, why is that Whatsapp and FB messenger can and will deliver notifications when you receive a message every single time, while for Skype this seems to be an unachievable feature?
Some real-life practical examples: knowing when a simple O(n) linear search beats O(log n) binary search, or knowing when a multiple substring search algorithm based on a simple Rabin-Karp and L1 cached hash table lookup will outperform the theoretically more optimal Aho-Corasick.
But as a senior developer, I daily have to understand the graph of code submitted for review to propose a simplified one to increase readability and ease future maintenance.
But does this mean you need to learn them by rote or be able to figure them out on a whiteboard? No. And although they appear regularly, I don‘t spend enough time on them that this would meaningfully affect my performance. So the time you spend thinking doesn‘t matter, very unlike a whiteboard situation.
Technical interviewing for long term employees based on exam essay like questions is rarely productive. My first objective is determining the applicant's honesty on their prior experience. It is amazing that the vast majority of applicants will out right lie on their resumes and to your face when questioned.
Past success in solving/implementing difficult projects is the best indicator of future success.
I'd wish more of those problems showed up in my daily work, though.
Btw, a cool popsci book about algorithms occuring in day to day life is "Algorithms to live by".
IMHO take home tests with a following discussion of the solution is the best way to go. Interviewers can judge the code quality as well as critical thinking with the follow up discussions.
Remember people processes need to be the least bad, not the best. Most of the best are either unworkable or tyrannical.
As for data structures, the only one I occasionally need to code myself is a simple tree.
even though real world problems are better interview questions, they suffer from requiring more candidate/interviewer prep. they can also stall out due to integration/machine/etc issues
Depending on where you are starting from, MIT opencourseware lectures might be helpful too.
(And you can pick up another book of his, The Data Science Design Manual[2] (direct PDF link[3]), which is similar in its conversational style, but about a different aspect of CS)
[0] https://link.springer.com/book/10.1007/978-1-84800-070-4
[1] https://link.springer.com/content/pdf/10.1007%2F978-1-84800-...
[2] https://link.springer.com/book/10.1007/978-3-319-55444-0
[3] https://link.springer.com/content/pdf/10.1007%2F978-3-319-55...
Does look like there's some interesting stuff in the article though, so I'll read it properly later.
For example, here is a shell script that takes an input file consisting of lines of the form
X Y
where X and Y are integers representing the X and Y coordinates of live cells in a Conway's Life grid, and outputs the next generation in the same format. It runs in O(n log n) where n is the number of live cells, and it is really just sorting. > alive.$$
while read cells
do
echo $cells >> alive.$$
set x $cells
x=$2
y=$3
echo $x $((y-1))
echo $x $((y+1))
echo $((x-1)) $((y-1))
echo $((x-1)) $y
echo $((x-1)) $((y+1))
echo $((x+1)) $((y-1))
echo $((x+1)) $y
echo $((x+1)) $((y+1))
done | sort | uniq -c > neighbors.$$
grep '^ *3' < neighbors.$$ | sed -e 's/^ *[0-9].//'
grep '^ *2' < neighbors.$$ | sed -e 's/^ *[0-9].//' > has2.$$
sort alive.$$ -o alive.$$
comm -12 has2.$$ alive.$$
rm has2.$$ neighbors.$$ alive.$$That has some aspects of software development that I rarely hear discussed, like testing, usability, accessibility, aesthetics, graphic design, error handling and recovery, documentation, support, configuration management, and lots of system framework knowledge.
If I am supposed to be writing apps for iOS devices, then I’d think knowledge of UIKit would be a heck of a lot more important than balancing a binary tree. I can tell you, from personal experience, that it takes a long time to learn, and is very important, if you want actual, shipping apps.
Even so, I have often encountered obsession with “büzzwürd du jour,” and people get hung up on things like MVVM/MVP, VIPER, etc.
I remember once, getting a “take home” test that asked me to implement an iOS app that employed MapBox, which is an excellent library, but, at the time, I had never used. I was instructed to use MVVM. I have no idea why.
In four hours, I had a completely functional, localizable, well-code-documented, nearly ship-ready (including a custom app icon and splash screen), high-quality app that implemented MapBox (again, I had never even looked at MapBox before this test), using Dependency Injection (basically, the “D” in “SOLID”). If I incorporate dependencies, I always encapsulate the dependency, and DI is an excellent way to do that.
Oh, also, while I was working on the app, we had a household emergency that required urgent attention. The app would have taken less time to write, otherwise.
It was not received well. To this day, I have never learned why. I suspect that I was supposed to spend a couple of days, creating some kind of chimera that illustrated every buzzword on Earth. No matter. I wasn’t what they wanted, and, after that experience, I realized I would probably not enjoy working with them; which was a bit disappointing, as I liked their product. I felt that I could have had a fairly significant impact on their Apple software.
In my experience, I have found it’s always best to use the development model a framework is designed to support; even if it isn’t particularly “buzzwordy.” If we use UIKit, then MVC is the most practical and simplest approach, as that is how the SDK was designed. If we use SwiftUI, then we have a great deal more flexibility with our models, but very few companies are willing to ship SwiftUI apps (yet).
Shipping is all about practical approach. Ship software should be done quickly, as simply as possible, and needs to be robust, well-documented, organized, testable, Extensible, and maintainable. If we are talking Apple apps, then they should also be performant, responsive, secure, highly usable, intuitive, aesthetically pleasing, accessible, and that employ familiar (to the user) idioms. They also need to pass App Store Review muster, so that means being careful about how we incorporate dependencies and frameworks, as well as not using private APIs.
Since I’ve had over twenty apps in the App Store that I’ve written from scratch (but I'm down to seven, right now: https://littlegreenviper.com/AppDocs/), this is something I do know a bit about.
That usually requires a great deal of frugality, practicality, user empathy, experience, and self-discipline. It’s difficult to figure that out with “Draw Spunky” binary tree tests.
If I'm asked to do a BFS/DFS, Tree traversal, etc for a small company.. I tend to share high level how I'll solve it then basically not actually code it up and say something like "This is pretty tricky...". Why? It's my way to exit the interview quickly because I question the ability of the company to hire talented engineers. Especially when I test your product out and see all sorts of inconsistencies.
Okay, so when do Data Structures matter to a company?
Are you building a product that needs to perform very efficiently at scale and the system is doing something outside the "norms" of what a data store can provide. Examples: Facebook's TAO system and their type ahead search.
Read the design paper for TAO and you'll see how they use very primitive data structured related to Graphs. Their typeahead system also makes use of some very basic data structures and some probabilistic data structures as well.
When do Algorithms matter to a company?
For most traditional companies, you're not going to do a BFS/DFS search, traverse a tree or a Dynamic Programming solution like Levenshtein distance. So unless these algorithms have a practical use case in your company, you're just creating a sort of monoculture.
Once again, Google and Facebook do apply these algorithms so I respect their interview process.
Big O has its place in such large companies. I think most people fail to understand the purpose of Big O; identify upfront if a solution will be sufficient from a time or space perspective as the data grows. Most people speak about Big O on interviews AFTER they code up the solution. You should do that before you code it up.
e.g, So the data for this problem is <100 items then this quadratic solution would work, but if we scale the data set up to say 10,000 items then it won't work. Then you can look at data structures or sorting algorithms for instance that'll help you get it down to say O(n) or O(n log n) etc
Look, I get the frustration a lot of people feel about this sort of interviewing process. I have a very non-traditional background and it could be very scary when you first start learning about this. My advice? Learn it for your own good. It'll make your a better programmer and it'll help you become more aware of so many things you weren't aware of before!
The moment when you realize why using an array for a Min Heap or why a Min Heap must be a complete tree... you'll step back and go "Now that's sexy!" Or when you realize even stupid stuff like "A balanced binary Tree has this weird reality that the leaf nodes account for 50% of all nodes in the tree" It's just fun if you see it in a positive way.
Let's call technical interviews that ask such questions when it doesn't represent the company "interviewer imposter syndrome". When a company tries to act and look like Google early on.. Google has a million+ candidates a year interviewing with them. They MUST allow good candidates slip through their process.
Next project was making a "Countdown" game, where you are given 9 pseudo random letters and have to make the longest word you can. I found a dictionary as a text file, so could see if the word you entered existed. The game was on Gameboy Advance, so not a huge amount of space or very fast CPU. As you can imagine, walking the entire dictionary file from start to end looking for a word was far too slow. So there was another ah-hah moment when binary search was introduced.
Next I worked on a rendering engine for this device called GP32, you basically got a pointer to the screen buffer and could put what you liked in it, so I learned how to write polygon fill routines, back face call, etc but didn't know what perspective projection was or how to find out about it. I finally found a book, Game Programmers Black Book or something like that, which explained perspective projection, at least to some extent, another ah-hah moment (previously I was dividing my XY by Z as I knew I wanted things smaller in the distance but this doesn't give a nice result by itself).
These are just very early examples when I first started programming, when information was harder to find, and when a lot of games development involved DIY, if you want a polygon you need to pixel fill a polygon! Even when PS2 came out you still had to write ASM render programs to take an array of vertices and transform them, their UVs, etc and send them to the Graphics Interface.
But I haven't found later tech developments have stopped me finding and needing to use other algorithms and structures. Just last week I had to diagnose a crash which resulted with the target device and debugger showing a nonsensical callstack, so I enabled the profile options in GCC/Clang so I had an epilogue / prologue for every function that is called, so I could store my own call graph history, and then, on crash, display it nicely, with indentation etc. This allowed me to see what happened just before the crash (turned out to be a system UTF16 conversation routine stomping over a pointers boundaries as the NULL termination of the string was incorrectly done as if the string was a normal char*, effectively NULL terminating half of a UTF16 pair, which wasn't treated as a terminate, so the actual bug was bad string termination done by the off the shelf engine we use). As the profile code ran twice for every single function that was run, it had to be pretty efficient, using appropriate data structures, etc.
So I guess the point of this post is to say I believe having a good knowledge of algorithms and data structures always seems beneficial to me. The extent which some companies push them is too much for me, but I don't think this should lead to us thinking it is all pointless. There is a nice balance out there.
For example if you use dict a lot in Python, that’s not at all the same as writing your own hash table with a custom chaining or probing algorithm for collision resolution.
The original quote from the whole homebrew saga is talking about needing to seriously implement these algorithms entirely yourself for a task. It was not talking about casually knowing a few fundamentals you loosely keep in your mind while using built in libraries.
Whiteboard hazing trivia interviews are also all about obscure implementation specifics, and they are not at all about knowing the coarse fundamentals. That was the entire point of criticizing Google’s parochial barrier to entry hazing crap.
While this author’s stated experience is cool, I think they entirely missed the point of what they are responding to.
However, you should be able to implement some of these more rarely used data structures, given a description. You shouldn't know how to do it ahead of time, however, because your job is to solve problems that aren't solved yet.
What you get with these interview questions is that some applicants prepare for how to solve some of these commonly posed problems specifically. So you have to implement a bug-free linked list, on a whiteboard, in ten minutes, to be competitive. It's doable if you are prepared, but that defeats the purpose.
no, in this thread people are describing actually hard, complex algorithms and ridiculous interviews. so sad to see that these questions are still being asked today.
this is the best thread on this subject that i have ever seen on HN.
Unfortunately some old school teachers whet not keen on dyslexia diagnosis