How to be Effective During a Code Interview
An interview starts at the moment you arrive in the meeting room or answer the phone or video call. How you behave and act during its time makes a lot of difference in the chance you have to succeed. If you want to increase your chances you should be well-prepared to do it. You can read this article about how to prepare and study for coding interviews. How you act and conduct the interview is also a deal-breaker in your chance to pass it. In this article, I will discuss some techniques and practices that can help you be more effective during code interviews. Here they are:
1. Try to manage your tension
I know that if you have practiced a lot and waited some time for an interview that you really want to pass you may feel very nervous and anxious when the day comes. My best advice to you is: keep calm. I know it is easier said than done, but how you prepare yourself internally for that moment makes a big difference in how calm you will be when it comes to doing it.
In order to keep you calm, you need to pay attention to how you’re acting before the interview. If you feel nervous take some time to do something that relaxes you. Trust yourself, you have already studied all you could. Don’t start reviewing any concept on the day of the interview. Instead, do something you like and that will help you clear your mind, e.g. do a yoga class, take a hot bath, take a walk on the neighbors, listen to calm music, meditate, etc.
Besides that, when the interview starts, if you feel too nervous, try taking deep breaths. There are a lot of studies and scientific evidence that show how powerful breathing can be to calm us down. You can also try speaking slower or any other methods you know that help you to be calmer. Just don’t forget to always manage your tension before and during the interview because for many people what gets in their way is nervousness, not the lack of knowledge.
2. Ask clarifying questions
When the interviewer tells you what code question you will need to solve they will give you a brief explanation of the problem. Listen carefully! After they finish the explanation, one thing that can help you a lot when solving it is asking clarifying questions to help you to better understand the problem and how they are expecting you to solve it. If some part of the explanation wasn’t clear for you that is the right time to clarify it.
Besides that, you must also ask questions to dig more about the problem. This step is very important to prevent you from making wrong assumptions. Let’s take this example:
Imagine your coding problem is ‘reverse a word’. Assuming the structure of the input is a string is a bad move if the interviewer hasn’t said that. It could be a linked list which would make some solutions that you may think not possible.
Therefore, don’t ever make any assumptions before asking the interviewer if you can assume that. Another thing that can help at this point is to create a use case and simulate how it would be processed until reaching the result. As you process it you can ask questions to the interviewer to make sure your assumptions are correct or to clarifying how the algorithm should work. This article has many possible questions you can ask, but here are some examples:
- Questions about possible corner cases
- Questions about the problem’s context
- Questions about a method input and output
“What is the expected input?”
“Is the input a number? Is it possible that it is a negative number? What about zero?”
“Is the input a string? Is it possible that the string is empty (“”)?”
“Is the input an array? Is it possible that the array has length 0?”
“Is the input a linked list? Is it singly or doubly linked?”
“What is the expected output?”
3. Explain your approach before coding
Succeeding the problem understanding you will start thinking about the solution. But… wait! You don’t need and even don’t want to jump to the code already. A very important part is to explain out loud your idea. Tell the interviewer what you are thinking before coding. If you prefer you can start with a simpler solution that has a higher time complexity, for example, and then iterate on it, by doing this, you enable the interviewer to follow how you evolve your ideas and build an improved solution. This is important because the interviewer will be able to understand what you are thinking, ask you questions, or even give you some tips on why your solution may or may not work.
Don’t skip this part even if you are afraid you won’t have enough time to code. Of course, the interviewer wants to know how you code, but normally what they want to know the most is how you build your reasoning. They need to understand the way you think and get to know your troubleshooting skills. Besides that, explaining your thoughts is an opportunity to take some time to make sure you are covering all cases, and if you notice that something may not behave as you expect it is a lot easier to change your approach before you have already coded it.
This is also a good time to think and discuss time and space complexity. If, for example, your solution has a good time complexity this is a good argument to explain why you choose to solve the problem that way. On the other hand, if you notice that your solution has a bad performance you may realize that perhaps you need to change your approach. Besides that, by talking about the algorithm complexity, you show that you cannot only solve the problem but also understand how your solution would perform in production.
What is important to say when explaining your solution:
- What you are going to do to solve the problem
- Why you think this is a good solution
- How you can prevent that corner cases won’t break your algorithm
Finally, it is time to code. My main and perhaps the most important advice from this article is to always say what you are doing and why you are doing it. It may sound obvious since you’ve already explained your approach, but there are a lot of ways to code the same solution, therefore the more your interviewer knows what you are thinking the better he will understand why you chose to do it the way you did.
Don’t forget to handle the corner cases you have already mapped on the above step and remember that the interviewer has to understand clearly what your code does, so don’t forget to code in the most readable way you can. After you finish, take a look if you didn’t forget anything and if you could refactor something to make your code cleaner. But be careful to not waste much time refactoring, if you notice that you should refactor many things you can just comment to the interviewer how your code can be improved.
5. Test your algorithm
Testing your algorithm is important because you can identify a bug that you haven’t noticed when coding. Ask your interviewer if you have time to test and show interest in doing it. If they say you don’t have enough time, you can just mention how you would test. If they say you have time, think of a test case and test your algorithm line by line to make sure it is working as you expect. Don’t take cases that are either too complicated or too easy. Think about a scenario that could potentially break your algorithm, but don’t choose something that would take too much time to test. Also, test all your code, don’t skip anything even if it is a simple operation.
Useful tip: write/type all the variables' values and change them during execution. If you try to memorize everything you can get lost and confused, so it is easier for you and the interviewer to know what is happening if the values are visible.
Those are all my tips and advice for coding interviews. Finally, the last thing I want to make clear is that all I have said were behaviors and actions that can help you to be more effective in coding interviews, but they are not rules that should be followed by the book, you must always think about adaptations that would work better for you.
If you want to keep reading about this content you can check out the article The Coding Interview FAQ: preparation, evaluation, and structure
Thanks for reading! I’m always open to receive feedback, recommendations, or questions, feel free to contact me!!
Clarice Abreu, Software Engineer
How to be Fully Prepared for Coding Interviews by Clarice Abreu — https://medium.com/quintoandar-tech-blog/how-to-be-fully-prepared-for-a-coding-interview-48b5eda4f440
How & Why to Ask Clarifying Questions at a Whiteboard Interview (for Junior Devs) by Mars E. Ikeda — https://medium.com/@marsikeda/how-why-to-ask-clarifying-questions-at-a-whiteboard-interview-for-junior-devs-97571fdc629e
The Coding Interview FAQ: preparation, evaluation, and structure by The Educative Team — https://medium.com/the-innovation/the-coding-interview-faq-preparation-evaluation-and-structure-607ac0225605