READING-NOTE

View on GitHub

programming interview

7 tips to ace a programming interview

1) Take a few minutes.

Don’t waste precious minutes trying to fill the silence by saying everything you’re thinking, while simultaneously trying to solve the problem in your head.

Instead, wait until the interviewer is done explaining the problem. Ask any clarifying questions, and then tell your interviewer:

“Okay, got it. If it’s okay with you, I’m just going to take a minute or two here and think about the problem, and then I’ll start talking.” Shut your eyes, stare at the ceiling, scribble on the whiteboard — whatever it takes. Think through the basics of the problem, and decide on an approach. Then re-engage the interviewer, and let him know what you’ve concluded. Don’t forget to provide your reasoning!

So, I think that, since the array is sorted, it makes the most sense to do something like a binary search here. Here are the general steps that I think are involved in the solution: …”

2) Write down the steps of the solution.

Start at middle of array.

Keep variables tracking left and right boundaries of search area.

If value equal to search_val, return true.

If left and right boundaries are adjacent, return false.

If value bigger than search_val, go halfway towards left boundary, and move the right boundary along with us.

If value smaller than search_val, go halfway towards right boundary, and move the left boundary along with us.

3) Write pseudocode first.

cur_idx = array.length / 2
l_marker = 0
r_marker = array.length
while (markers are more than 1 apart)
  if array[cur_idx] === search_val
    return true
  else if array[cur_idx] < search_val
    cur_idx goes halfway towards r_marker
    l_marker = cur_idx
  else if array[cur_idx] > search_val
    cur_idx goes halfway towards l_marker
    r_marker = cur_idx
return false
function binarySearch(search_val, arr) {
  let i = arr.length / 2;
  let l_marker = 0, r_marker = arr.length;
  while (r_marker - l_marker > 1) {
    if (array[i] === search_val) return true;
    else if (array[i] < search_val) {
      i+= ((r_marker - i) / 2);
      l_marker = i;
    }
    else if (array[i] >search_val) {
      cur_idx -= ((i- l_marker) / 2);
      r_marker = i;
    }
  }
  return false;
}

4) Don’t sweat the small stuff.

If you can’t remember something like this, it’s often acceptable to say that you’d look it up.

“…and here, I’d use whatever the list.contains() equivalent is in JavaScript. I know it’s not contains, but I can’t remember the method name right now, so we’ll call it contains() for now and I’d look it up right now if I were coding this.”

Let’s be honest, half of being a programmer is knowing how to Google stuff and how to interpret search results. We use the internet as a giant cache for all the information that we “almost” remember but don’t bother to, since we can just look it up at any time. It’d be hard to fault an answer like the one above. So don’t waste time memorizing keywords in your interview prep. Focus on the big picture.

5) Sit down. Be humble.

Are you able to express your ideas and solutions clearly and effectively?

Do you treat the interviewer with respect?

How do you accept criticism (technical, constructive or otherwise)?

Are you able to collaborate with others to come up with solutions?

Do you communicate in a way that demonstrates empathy?

Are you honest (especially about yourself)?

6) Come prepared.

In the interview, knowing that you’ve done all you can to prepare helps you stay calm and cool, and increases your chances of success. And afterwards, regardless of the outcome, knowing that you could not have reasonably done more to prepare helps you feel proud of your work and start moving towards your next goal.

To pretty much everyone that I coach through interviews, I recommend the same personal interview prep bible: Cracking the Coding Interview, by Gail Laakman McDowell. Like myself, Gail’s been at Facebook and Google, but as a former member of the Google Hiring Committee, Gail is qualified to speak authoritatively on the software hiring process (and able to speak in detail about the Google hiring process, which I cannot due to my employment contract).

This book’s been around for years and almost every engineer I’ve met at Google or Facebook (including myself) has completed it cover-to-cover. If you want to get the most value out of your HOBIS, I cannot recommend CtCI enough. No matter what material you use, make sure you get enough HOBIS and your next interview will be a much better experience.

7) Review your work.

Think about how silly you look if your solution is not right.

Instead, if you have the time, review your code as you would in a peer review. Show the interviewer that you are committed to producing accurate, high-quality work, and that they can trust you to do so without being prompted.

In particular, focus on these two areas, as they receive heavy scrutiny in interviews:

Algorithmic efficiency. Have you found the fastest and most optimal solution given the requirements? Take some time and consider other approaches. It’s worth noting two things here: 1) If the problem involves a sorted dataset, you can bet your pants there’s a solution involving ` O(log(n)) lookup time (even if there’s additional cost, the total complexity will still contain the log(n), for example, O(n * log(n)) if iterating over an array, as sorting algorithms do), and 2) For a disgustingly large number of programming interview questions, the answer involves a hash table and O(1) lookup time — so if you’re seeking a better algorithm, try a hash table. Correctness. Sure, you’ve solved for the simple, easy use case, but have you checked for edge cases? Off-by-one errors? Issues with negative numbers or empty arrays or missing keys or strings with weird patterns of characters? Maybe you won’t find all of them, but failing to at least LOOK for edge cases before declaring your solution to be correct is a pretty hefty mistake in an interview.