Coding Interview Guide

Coding Interview Picture

Advanced degree in computer science? Check.
Good marks in school? Check.
Years of professional experience at prestigious tech companies? Check.
Okay, just solve this programming riddle while an interviewer looks over your shoulder. By the way, the interviewer just added “it’s an easy question” ie. if you don’t solve it in 10 nanoseconds you’re an idiot.

Coding interviews are pretty hated, but you shouldn’t let them stop you from getting your dream job. This post gives my advice for dealing with coding interviews. Here’s a quick summary:

Do you need to do coding interviews?

A lot of people complain about coding interviews, but for better or worse they’re part of the game. I’ve seen people complain about it, fight it and even refuse to play. The quickest phone screen I ever conducted at Amazon was with a senior engineer. After the small chat, I switched tracks to start the coding portion of the interview. He got angry, said he had a lot of experience and refused to do any coding in the interview. Well, John Carmack is above coding interviews, but you’re not. There are a few companies out there that don’t do coding interviews, but you’d really be limiting your options. If you’re going to be a software engineer, you need to be judged like a software engineer.

But what about your algorithm class marks? Profession experience? Github repo and references? Unfortunately, I’ve never once, in any company I’ve worked at, heard a peep about a candidate’s marks in school or how clean their side project code was. That’s because we’ve all seen people that look amazing on paper but are incapable of demonstrating programming skills.

If you’re coming from an ML background, there’s been a push to separate ML Engineers from Analysts. The ML Eng role has become more prominent (and generally pays a lot better.) However, this has the added requirement of passing software engineeringing interviews. That means lot of people coming from an analytical background are approaching coding interviews for the first time.

How Important are Coding Interviews?

The good news is that coding interviews have become much easier over the years. Companies are absolutely lowering their bars, but they’re also easing up on unnecessary requirements. The fact is, coding interviews don’t really reflect what day to day life is like as a software engineer. I’d say they’ve essentially become binary, at some companies their outcome is explicitly binary: pass or fail. Either you do good enough (and not necessarily perfect) or you fail. This is especially true as you become more senior, and past experience, behavioural questions and systems design interviews become more important. Unless you’re joining as an entry level engineer, coding questions will basically only disqualify you, they won’t get you the job if you have other weaknesses. I think that with some studying and practice to calm the nerves, every decent candidate can essentially remove coding from the equation of whether they’ll get hired.

Under Pressure

To me, the most artificial aspect of a coding interview is the pressure and time limitations. These questions are riddles, and your brain typically needs to be in a relaxed state to think creatively and solve riddles. This is one of the things that have thrown me off. Here’s my advice:

Studying Approach

I’ve always been good at algorithms and data structures, it was one of my best marks in school and I’ve programmed/studied these concepts for a long time. I learned that you need to go beyond a passive knowledge of algorithms and data structures excel at interviews. A book that shaped my approach to interviews, which I highly recommend, is Elements of Programming Interviews. This went beyond random practice questions to a much more structured approach. Questions are organized by CS concept, which helps show you how to utilize and internalize concepts like binary search and heaps.

This is why I believe studying for programming interviews isn’t a waste of time to game the interview process. By internalizing how to use different algorithms and data structures to solve problems, you’ll become a better software engineer. Essentially, every few years when you look for a new job, you go through the process of studying and rebuild those muscles, even stronger. The concepts are all timeless and applicable, so it’s very useful. Learning the trick for how to find the best possible trade given a timeseries of stock prices isn’t timeless, studying and understanding how to apply data structures absolutely is.

Unfortunately, coding interviews lean on different skills than you typically use at work or exercised in school. So it’s important to study ahead of time to give yourself a leg up. Like I mentioned earlier, it’s a worthwhile investment in your skills. Here’s my recommendations:

Interview Signals

Companies are looking for a few signals in a coding interview.

Coding

The most crucial skill to demonstrate in a coding interview is the ability to cleanly code a desired behaviour. It doesn’t matter if you did a phd on cuckoo hashing, if you’re struggling with list comprehensions then you’ll fail. If you don’t come from a programming background, this can be kind of hard. Some interviewers are checking for language mastery, while others are just looking for pseudo code. Make sure you’re clear on expectations ahead of time. If you’re coding in a real language, I’d recommend using Python. It gives you a speed advantage for coding and most engineers know it.

CS Concepts

These are the Computer Science concepts that you should focus on for coding interviews. Of course the field has a lot more to it, and they may even come up in interviews too.

Data Structures

Data Structures are more important than algorithms. For most coding questions, the main insight will come from figuring out what data structure can be used to represent your data. This requires knowing the data structures by heart so you can cycle through options in your mind. Think about how you need to access your data, do you need to insert items in random locations? Do you need to scan the data in sorted order?

Algorithms

Complexity

You will definitely need to know how to estimate the big-O complexity of your solution, both in terms of memory and run time. You might be dreading this, thinking back to proofs from your undergrad classes. It’s simpler than that, with practice, you see patterns that emerge, often based on the high level concepts of different data structures and algorithms.

Tips: There’s basically 3 options in a coding interview: O(1), O(log(n)) and O(n). Are you modifying a tree? Think O(log(n)). Are you looking at every item? It’s O(n) Make sure you know what N is for your question, since sometimes there’s more than one input Look out for hidden constant solutions. If you limit an algorithm to looking at a max of 10 items, that’s a constant run time (it doesn’t increase with the size of the input.) Don’t forget that complexity applies to memory too. There’s often a trade off between faster run times and memory storage. Make sure that you’re the one calling this out, not the interviewer.

Problem Solving

Interviewers are also getting a sense for how you solve problems and what it’s like to work with you. Do you take hints? Do you get defensive on hearing feedback? I can’t tell you how many times candidates have sunk their chances by reactiving poorly to feedback. The interviewer is trying to help you by focusing on a better solution, but many candidates will get defensive or stay stuck on their current track. It’s also important to vocalize your thought process so that the interviewer can get a sense for how you deal with problems.

Software Engineering

In the context of a programming interview, software engineering is evaluated pretty superficially: variable naming and classes/functions organization. It seems like this aspect of interviewing has really fallen in importance over the years. You don’t see many questions on OOP or Gang of Four patters. The nature of coding interviews usually yields some messy code and abstractions. Interviewers are pretty lenient to this I’d say, as long as the candidate can call out how they’d refactor the code to be cleaner. It’s also good to avoid red flags (eg. poorly named classes or exposing public variables unnecessarily.)

Approach

Okay, the interview’s started, you’re done talking about your last project and the weather, now it’s time to get to business. The interviewer describes a question to you and you’re staring at a blank screen on CoderPad. Unfortunately, this isn’t the question you studied last night, so you don’t have an instant answer. Now your nerves are kicking in. How do we deal with this?

  1. Make sure that you understand the question. It might make sense to go through an example input and desired output if the question isn’t straightforward
  2. Ask about corner cases and assumptions, how do we handle a negative price value? Can we assume this is single threaded?
  3. Speak out loud about an approach, just to make some progress. The most straightforward thing to start thinking about is how you’ll represent the data as a data structure and what behaviour you’ll need to do
  4. Once you solidify an approach describe it to the interviewer to get their buy in
  5. Code the question, narrate this a bit if you can to describe your thought process or any coding choices you’re making. Definitely call out things that you’re doing for interview processes.
  6. Before saying “I’m done!”, talk through the code a bit to catch obvious bugs. This is often something you’re evaluated on and shows maturity. Look for easy corner cases, what the input is an empty list.
  7. Finally, talk your way through your solution, perhaps ask if any unit testing is expected. It doesn’t hurt to help, and often you’ll be asked to think of how to test the code you’ve written. If you’ve gotten this far, you probably passed the interview. However, the interviewer might add in an additional request or ask about a more optimal solution. Sometimes you’re expected to code this, sometimes you’ll just talk through it.

How to get unstuck:

The goal of any interview question is to make you go through a problem solving process. This means you’re supposed to get stuck and have an ah-ha moment. However, it’s an incredibly uncomfortable feeling trying to conjure up a eureka moment under pressure. There’s a few ways to get out of this.

Conclusion

Thanks for reading to the end and I hope this guide helps you out. Take the marathon approach to prepping, you’ll learn useful knowledge and this is a skill you’ll revisit throughout your career. Coding questions can be very stressful, so don’t feel bad or fear failing. It’s better to fail, study and learn than let the fear of interviewing hold you back from the dream career you deserve.