How to Ace your Next Data Structures and Algorithms Interview?

This article is contributed by Bharat Khanna, Co-founder of Programming Pathshala, who has previously worked at Tower Research Capital as SDE-II.

Lets begin with the preparation!

There is no substitute for preparation. Make sure that you have prepared for different variations of commonly asked data structures and algorithms in interviews like stacks, linked lists, trees, dynamic programming, etc.

To make sure that your preparation is good, practice a lot of problems on various platforms like Leetcode and Codeforces. You can also opt for a guided courses like Renaissance at Programming Pathshala where you get taught by people who have already got into great companies like Amazon and Tower Research Capital.

One more important thing to note while doing the preparation is to not simply cram the solutions of some common problems. But, a better idea is to make sure you develop a knack for problem solving by understanding different problem solving techniques and the kind of problems these techniques can be extended to.

Once you are well prepared for the interview then there are a few steps which you should take care of during the interview.

Make sure you introduce yourself well.

Introduction is very important for making the first impression on the interviewer. Make sure your introduction is crisp and precise and it definitely mentions your interest in data structures and algorithms. This will prompt the interviewer to majorly focus on this area during the interview.

Discuss strategy first

It is not a good idea to be quiet for a very long time during the interview and then suddenly start typing the code out. The interviewer would not be able to understand your idea and thought process behind that particular implementation.

Also, long pauses during the interview makes the interviewer confused if you are even in the right direction. If you communicate well with the interviewer, he will be able to give you hints that guide you towards the solution. Which brings us to the next point.

Make use of hints given by the interviewer

Let’s say you are suggesting a solution which uses Two Pointers technique and the interviewer hints to think about the other thought which you mentioned earlier that involved the use of Binary Search. Then, maybe he/she is looking for a Binary Search based solution.

This cue should be enough for you to abandon your trail of thought related to Two Pointers and focus on where he/she wants you to go. It is not a good idea to keep sticking to your initial ideas and not move on. This leaves a bad impression on the interviewer. They would think that you are not good at picking cues and may not be a good listener.

Discuss Time and Space Complexities

The only way to compare multiple approaches in a Data Structures and Algorithms interview is based on time and space using Big-O notation for measuring time and space complexity.Make sure you have thorough ideas around these estimations and you mention them for every approach you discuss with the interviewer.

The interviewer can ask you to reduce either time or space if he is not satisfied with the current approach. Generally we move on to the coding part once both the interviewee and the interviewer agree on one most optimal approach to implement.

Write Clean Code

Many people take the coding part of the interview as the part where they have to deliver very quickly and move on to the next question. But, remember, this is not a coding test or a competitive programming contest where the one who codes first will win. This is an interview where more than speed, it is important that your code is easily understandable to the interviewer.

Ensure that your code is modular with small reusable functions instead of being a big blob of code. Also, make sure that the names you give to different variables are not just i,j,k,etc. The variable names should have some meaning to them rather than just being illogical symbols.

Handle corner cases well

Another important mistake that people make while writing codes related to Data Structures and Algorithms is that they miss out corner cases like Linked List being empty, Binary Tree not having one of the two children, an Array having negative elements etc. It is very important while preparing to make out a list of common edge cases that you generally miss.

In the interview scenario as well, it is a good idea to revisit your code and see if it is working on some of these common corner cases. Make sure that these cases are not missed before telling the interviewer that you are done with the code.

Dry Run the Code on Initial Given Test Case

One last but important step in an interview is to actually dry run your piece of code on the given input so that the interviewer gets the perfect idea of how your logic is working with the help of examples. Wherever in your code, you have multiple code branches, make sure to give him an idea as to which cases will end up in those branches.

Now you can become 100% Coding Interview Ready with Renaissance!
Take a free trial here and begin Today.

We are working to democratise access to Tech Education. We help students learn coding and be confident about themselves.