One Tip to Crack the Coding Interview — Use Abstractions! | by Minhaz | Feb, 2022

Based on five years of my interview experience

Minhaz
No hush, mistakes are learning opportunity!

I have been taking interviews for Google and Microsoft for around 5 years and in my mind, this is likely one of the most common mistakes, I see several promising candidates make.

I am talking about a typical programming interview here — one where you are given one or more problem statements and are expected to arrive at an optimal solution (algorithm) and write code for it within 45 to 60 minutes.

These are generally called Data Structures and Algorithm interviews” and most of the major software companies use this kind of interview to hire software engineers from entry-level to senior hires.

After taking several interviews, of candidates from 0 to 12+ years of experience — there was this one common problem leading to a bad impression and potential rejection.

The candidate attempts to solve every part of the question rather than focusing on what is important.

And in many cases, the candidate ends up not solving the given problem. Sometimes the candidate gets tangled up in an unimportant subpart of the problem.

If the candidate is interviewing for a junior role, I don’t mind this and I usually steer the candidate back to the problem at hand before it’s too late. But when hiring for intermediate or senior roles there are two important signals I like to analyze:

1. Can the candidate break down the problem well and address them independently.

And in case the candidate jump to the potentially long path.

2. Can the candidate step back and think rationally

How I look while taking an interview as per my wife!

Let’s take the example of LeetCode problem 165 — Compare version numbers

Given two version numbers for example “1.4.5” and “1.3.6” return the greater one

On its own, it looks like a fairly simple question. Before the candidate is about to start coding — I explicitly mention:

One of the most common approaches is to split the string with “.” As a delimiter and convert the values ​​to integer and then compare left to right, assuming the given values ​​are valid version numbers.

For this specific question, I have seen several C/C++ candidates spend too much time on the first subproblem — splitting and converting string to integer array.

In C++, many candidates write some version of the following code.

One way to address the first sub problem of the interview question in C++.

I have seen some candidates finally getting through with this subproblem one way or another while a couple of them getting stuck writing code for this.

And you have got a total of 45–60 minutes

The question was to return the larger version number.

I see many candidates not being able to finish the code for the question in the given timeframe. I haven’t asked this specific question in a really long time but time and again, I have seen candidates trying to solve the given problem without breaking it down and focusing on the key components.

If the candidate is interviewing for intermediate to senior roles —this gives a bad impression, to me as an interviewer. During the course of the interview, I need to see enough signals from the candidate around the algorithm and data structure skills, coding skills, design skills, and efficacy to solve the problem and this can be a red flag for the last two verticals.

When you start to write code during an Algorithm or Data Structure interview — try to write the top-level code and make assumptions on the interfaces and helper methods.

Start solving the key part of the problem — you can even ask the interviewer if you are expected to solve a certain sub-problem or you can assume it is implemented. If the interviewer needs more signals, they’d ask you to write code for the sub-components.

It’s always better to finish the code for the required question than not!

Leave a Comment