Algorithms & Coding Interviews

Algorithms & Coding Interviews

June 22, 2018 Interview Uncategorized 0

In today’s blog post, I will be discussing the importance of understanding algorithms in order to crack technical interviews.

ALGORITHMS

Algorithm is basically a sequence of steps to solve a given problem.

This is the single most common thing that you will be asked in an interview.

Algorithm problems in technical interviews

Algorithm problems

 

Whether the question is related to some sorting or searching, some manipulation of data structure, or some other problem, what the interviewer expects from you is the sequence of steps which you can enunciate and then code.

The word “Algorithm” tends to scare candidates some times. The problem the candidates face is: how to come up with the most efficient solution to a given problem in such a less time. You have heard the problem for the first time. You have the pressure of the interview on your head. They are constantly staring at you, and so on.

Well, the answer is very simple: you don’t have to come up with the best solution. You only have to come up with the most basic solution. Even if it’s not the most efficient, you just have to explain a solution that works. Once you have that and are able to explain it well, it validates that your solution at least works. You validate that you understood the problem correctly and are on the right track. Once you have the “basic” solution ready, you should be able to talk about the efficiency of your solution. And once that’s done, then you can improve the efficiency of the solution afterwards.

One of the most common mistakes that candidates make is when they hear the problem, they have a solution in their head, but they don’t speak it. They think that since it’s not the most efficient solution so the interviewer will not like it. So they keep the “crude” solution with themselves and never talk about it. On the other hand, for the interviewer, it means that the candidate never had a solution. According to the interviewer, you can’t come up with even the most basic solution to the problem.

So for candidate, the approach should be to talk about the solution you have in mind. Explain it’s time and space complexity in terms of Big O notation. Once you have explained this, then you can improve the solution afterwards. This at least gives you more than 50% points. Once you have reached this step, the interviewer will guide you to find the better solution. They will give you hints on where and how you can improve the algorithm.

This is a process in itself. If you try to skip the process and try to come up with the “best” solution in your head, this gets counted against you. The interviewer wants to see your problem solving approach. By going through these steps, you are demonstrating your ability to come up with a solution quickly and then improve it by discussing with other people.

Imagine yourself in the real work environment,you don’t want to hire someone who hears a problem and then goes back to their computer and tries to come up with a perfect solution by oneself. Instead what they want is your ability to enunciate what you are thinking and let others help you and guide you to come up with the best solution. It also demonstrates your team skills and ability to keep everyone on the same page.

HOW TO PREPARE

In order to prepare for algorithms related question, the only key is the practice. You need to learn how various algorithms work. You should be familiar with the most common algorithms related to Sorting & Searching. For example, Merge Sort, Quick Sort, Breadth First Search, Depth First Search, etc.

Other than that, you need to practice various interview questions and learn the common techniques that help you optimize the solutions.  Some of the common ones are runner technique, memoization, using the optimal data structure, etc. This skill will come mostly with practice. Once you have done lots of practice on similar problems, these techniques will automatically come to you as second nature. You will not have to think about these techniques explicitly.

CONCLUSION

Good understanding of algorithms and their efficiencies is crucial to be able to crack technical interviews and justify your decisions to choose one algorithm over another. This is going to be the most crucial factor in getting success in technical interviews. I will be covering more of algorithms related questions & techniques in my future blog posts. Until then Happy Coding 🙂