A practical way to handle technical interview questions
Technical interviews are really hard where many people struggle. It even gets harder for product-based companies. One of the hardest parts of this is how to proceed with the problem thrown in front of you.
What is the reason behind this case? Poor DS-Algo?
No, that is not an exact reason. DS Algo is just another alphabet for the technical interviews. Let's say you have solved 400+ leet code problems and practiced many design-related problems. Still, people see failure. Why?
The real challenge is not to have a planned framework to approach and answer these types of questions. You remember in school days we were taught guidelines to answer questions. How will you format the answers, what will be heading, where will be the diagram etc. So in any exam pressure, we could effectively write out answers. Handling these technical questions with a preplanned technique can bring a big difference in your interview score.
In the interview, the first goal should be to convey your worth to the interviewer. Here in this post, I am not going to discuss data structure and algorithm problem-solving techniques. However, I will share the steps to handle these questions effectively.
Well, what is that technique?
Before answering technical questions keep in mind the REACTO technique.
Hmm, What is the REACTO technique? REACTO is a strategy for solving technical problems.
R stands for Repeat: Yes you have to repeat the question which the interviewer has asked. You have to rephrase the problem in your word so that interviewer can know about your understanding, and you both can start to follow from the same page. Make sense? Read on…
E stands for Example: Now your task should be to get some examples and discuss this with your interviewer. This will help the interviewer to understand your logical and rational thought you can think of. You will come across many edge/corner cases when you start writing.
Wow That's interesting…. Next A.
A stands for Approach: Once you have followed the above two steps then you must have got some intuitive feel for the problem. How would you approach, the tools and technique which you have to follow for this problem, nature of the problem, etc? These all details you must have got while just following the above two steps. Share your approach with the interviewer. In a healthy interview, the interviewer will let you know that your approach will work or not. after all, he is the person who has prepared this in advance isn’t he. This is half the battle-won situation.
Coding: Now this is the fourth step where you have to crush your keyboard and show all the DS-Algo, design pattern, and coding skills that you have acquired.
Test: This is the auditing of the code which you have developed. Discuss all the corner cases here, and walk the interviewer through the code line by line.
O stands for Big-O: Yes this is another very important tool to gauge the efficiency of your code both in terms of space complexity and time complexity. Always evaluate the time and space complexity of the code which you have written.
All the above steps will conclude a good technical interview.
Just for demonstration, I will walk you through an example and how we can follow it in the interview.
Let's discuss a general popular interview question balanced bracket validator:
Problem: you are given a string with opening and closing characters, and you have to validate if the string is balanced. (Balanced means all the opening characters are closed properly with the same type).
Opening characters : (, {, [
Closing characters : ), }, ]
Let's say the interviewer just asked you this question, and nothing else. How would you go to drive the discussion further?
Let's follow our REACTO technique:
R:- Read,
Reread the question again yourself. you are given some string that has known characters (opening and closing). These characters are arranged in some random way. If an opening character has its corresponding closing character, then this is considered a balanced one else string is not balanced.
E:- Example,
while reading the problem statement you might have thought to write your findings on paper or somewhere. Take some examples. You are given a string with some known characters (opening and closing). There are a lot of possibilities that could occur right?
- {{}} :- This is balanced. All the opening characters have the corresponding closing characters.
- {()}[] :- This is balanced again.
- [{{((]}}}:- This is not balanced. See the first encountered closing character in bold ] has ( as an opening character.
- {{{{{{{{:- with no closing character. This can be an edge case? While thinking the word edge case/ corner case we again get the idea that hey what will happen if there are no characters?
- “”:- just empty one or only closing characters?
- }}}}}}}
You have just seen that writing the example has helped you to think through the bigger picture of the problem. you have seen you got so many questions to discuss with your interviewer. isn’t it?
A:- Approach,
What do you think? How can you approach this problem? Intuitively you might say that we will scan the input string from start to end while keeping track of opening and closing characters. Hmmm. yeah, keep track….
You:- what will you keep track of?
Brain:- We have to keep track of the opening characters so that we can check if they have closed properly.
You:- What will you do with those characters?
Brain:- We have to store the opening characters in some data structure so that we can check if they have closed properly.
You:- What data structure we have to choose?
Brain:- Hmm, Let me scan all the data structure in my memory. yeah, I got that. When I find a closing character, the recently seen opening character should match with this closing character. So we have to get the most recently added one in constant operation or the last processed item in the constant time. Yes, We need a stack. Last in first out. The last seen character can be accessed in constant time. Isn’t it?
These many questions have given you more insight to solve the problem.
So now we can create an algorithm:
Step 1) If we see an opening character we have to store them in DS (stack).Step 2) If we see a closing character we have to see if the top of the stack has the associated opening character.Step 3) If the stack top has matched with the closing character we remove the top of the stack else we conclude that the string does not has balanced characters.
We go iterating the above three steps until we scan the entire input string.
Once you discuss this with the interviewer you might get some more insight.
Consider the below example:
}}}}
You are given only closing characters. In this case, there won’t be anything in the stack right? So you have to modify the algorithm to consider this case as well. This case makes your string invalid. So in step 3, we have to check if we are not getting valid opening characters for the corresponding closing character or if we have an empty stack while there are some unprocessed closing characters still present then we have to conclude that the string does not have balanced character.
C:- Code,
Next, you can write the code in your favorite programming language, and audit that line by line.
That's it, I am not going to discuss the other two parts that are test and big O notation. That's very intuitive. The purpose of this article was to give you an insight into problem-solving using the REACTO technique.
You have just seen how effective this technique could be. Once you practice following this technique things will get smoothen. Remember in a healthy interview, the interviewer always guides you for the blocker. They just observe how effective you are in thinking. Writing code and the solving problem is not an hour task. Sometimes in the real world, you end up solving a problem for a week or for several months.
Happy Learning!!!