I don't remember how to balance a damn binary search tree, and that's perfectly OK
Disclaimer: I am not currently looking for a job, these are only my thoughts from my own experience with interviews (on both ends).
There is a style of technical interviews (popularized by Google and because it’s Google it has to be right) that reduces the technical interview to an exercise in how many data structures and algorithms one can remember from their college days. Add to that a bunch of logical puzzles and riddles and it starts to feel like an IQ test and not a software engineering job interview.
I am not necessarily saying that those questions are irrelevant to computer science (they are relevant), however they are mostly irrelevant to the job I am applying for and to the work I will be doing if I ever get the job.
That being said if for whatever reason your company wants to conduct that sort of interviews and you truly believe that they are a good assessment of someone’s programming skills then that’s perfectly fine, I am not here to convince you otherwise, but at least make it clear to the candidate before the interview that you will be asking those kind of questions so the candidate can be prepared.
Questions about how to implement quick sort, merge sort and heap sort and what their time and space complexities are, are not questions about programming skills, they are questions about memory skills. You are not asking the candidate whether they know how to implement such sorting algorithms, you are asking them whether they remember how to implement them. Anyone who is capable of implementing those algorithms have seen them before at some point. If by any luck they remember them they will get the question right, otherwise they are screwed. No body is going to come up with an implementation of heap sort in an interview on their own if they have never heard of that sorting algorithm before, simply because those algorithms took years to develop and no one is going to come up with years worth of research in a 5 minutes interview.
This reminds me of Rod Hilton’s excellent post about how much he despises the infamous “find a loop in a linked list” interview question because the tortoise-and-hare optimal solution actually took 12 years to develop and yet the interviewer usually expects you to come up with that solution in 5 minutes. Anyone who comes up with that optimal solution in an interview has heard that answer before, and if they haven’t then they are either lying to your face or deserve a Turing award.
See when I was in college I got an A in my data structure and algorithms class. I could invert a binary tree blindfolded and balance a binary search tree in under 60 seconds. I could talk to you for hours about all the different sorting algorithms and their average, best and worst time complexity. Now if you ask me the same kind of questions I will simply draw a blank. Does it mean I was smarter then and got dumber as I got older? not at all, it just means that I haven’t been studying those topics. I don’t use them in my daily job. I simply forgot. I haven’t used them in over 9 years since I graduated. I have never faced the problem of implementing a stack using two queues in my career. Matter of fact I never had to implement a stack in my career. I don’t even remember half the code I wrote 6 months ago and yet you expect me to still remember the materials I took in college 9 years ago. Even if there was a tiny part of my brain that vaguely still remembers that problem I guarantee you that that part is going to forget all about it under the stress of an interview (which is usually a nerve racking experience by itself).
In the unlikely possibility that I ever need to balance a binary search tree in my job I will just look it up online. I guarantee you that I will find the solution in under a minute. Or even better use a library to do it. There is just no reason for me to know how to do it off the top of my head. On the other hand I didn’t have such luxury when I was in college. Looking up the solution online was not an option in my finals. I had to know how to answer the question from memory. Shouldn’t your interview be more about what I would do if I faced that question in my real job and not if I faced it in a college exam?
If you are an employer and after reading this you still want to conduct such interviews then at least be fair to the candidates and give them a heads up about the nature of the questions you will be asking so they can brush up their knowledge of such topics. Data structures and algorithms is a broad topic and it can take months to study up for them, depending on how much you still remember from your college days. Which leads to my next point, how bad do you want the job that you are willing to spend the next few months of your life studying up for it? I personally don’t think I ever want any job that bad (unless maybe if it paid me a ridiculous amount of money) but even then, am I guaranteed to get the job even if I get all the technical questions right? not necessarily. The position may no longer be available, I might not be seen as a cultural fit…etc. There are tons of reasons I might get rejected for, heck I might even get rejected for no reason at all or simply just be ignored and not hear back from the employer. Are you willing to take the risk? and even if you do get the job, most of the knowledge gained from your interview preparation will probably be all forgotten in few months after you realize how little it gets used.
See the reason I spent hours studying up for my algorithms and data structures class in college is because I wanted to pass the class. I had to. It was a required class towards getting my degree. I wanted my degree. I was willing to make that kind of investment and sacrifice. At the same time I was also guaranteed that my exam paper will be graded and I will get feedback on it. I was guaranteed that if I passed all the tests I would pass the class and eventually guaranteed a degree. There was no risk. That made it a lot easier for me to keep motivating myself to keep studying and working hard. A job interview can never make any of those guarantees and yet you are expected to make the same amount of investment and commitment.
Maybe such interviews are fair to fresh graduates since that material is supposed to be still fresh in their heads but it is absolutely not fair to experienced professionals. Just like most experienced candidates would draw a blank when asked unprepared to implement a Prefix Tree most fresh graduates would draw a blank when asked questions that most experienced software engineers would find trivial like unit testing, object oriented programming, continuous integration and agile development. And if you are an employer who insists on asking algorithmic questions to everyone then at least be fair and let them know what to expect. Give them a chance to prepare. Algorithmic questions are not hard. They are not necessarily any harder or easier than object oriented principals. Matter of fact most algorithms can be implemented in very few lines of code. You just need to remember how to do them. I don’t care how good of a programmer you are, you do need to prepare and study for them. They take a certain mindset to solving them that you rarely get to use in your professional career.
There are many books online that prepare you for such interviews. You can simply buy the books, spend a couple of months studying up all the questions and puzzles there and chances are you will be in good shape to pass those kind of technical interviews. If this all sounds very similar to standardized tests (GRE, SAT..etc) is because it is. You need to spend months studying for standardized tests. No body can walk into a GRE exam unprepared. I don’t care how good your English and math skills are, you have to prepare for it. And if you do pass the test does it mean you are a good mathematician or a proficient English speaker? not necessarily, it just makes you good at that kind of questions because you have invested the time and effort in them. Maybe Computer Science should have similar standardized tests so that companies would stop asking those questions again in an interview.
Does Google have brilliant engineers? Absolutely. Does it mean their interview process works? not necessarily. Think of all the brilliant engineers that were turned down by Google because they couldn’t answer their algorithmic questions. Max Howell, a brilliant programmer who wrote Homebrew was turned down at Google because he couldn’t invert a Binary Tree on a white board and famously tweeted “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.” He then went to join Apple. Good for him.
Also who said that all engineers in Google are good? Look at many of Google’s failed products. Google+ anyone? I bet whoever came up with that brilliant idea was able to invert a binary tree on a white board in no time. What good did that do to him and to Google?
So what are some appropriate questions to ask during an interview? I think the best questions are the ones you don’t have to ask. Look at a candidate’s GitHub account, their contribution to open source software, any books they wrote, their blog, heck even their twitter feed. That should be your best tool to assess a candidate’s technical abilities.
My favorite technical questions are take home questions. Write a Tic Tac Toe game, design a drag and drop JavaScript component, write a chat client server. Give the candidate a few days and see what they come up with while they are not under the pressure of an interview. It will tell you tons about the candidate’s technical abilities and programming skills and it will open up many topics for discussion.
It is also generally fair to ask candidates about stuff in their resume. Ask them about the last project they worked on and what they enjoyed and what they didn’t. If they are Java developers for example ask them what they like and hate about the language. Get a sense of what they like to do and what their strong and weak points are. Just for God’s sake don’t ask them to invert a binary tree unless you have specifically prepared them for it. Do you by any chance see on their list of skills “how to invert a binary tree”?