Menu
computer science

How To Approach Coding Interview Questions With Confidence + Practice Tips

Tips To Master A Coding Interview

If you are preparing for a coding interview to land a job in your dream software engineering or related role, it’s normal to be prone to impostor syndrome. Why am I failing to crack the coding interview despite preparation? How can I avoid getting nervous while solving a coding interview question? What are some tips to approach coding interview questions with confidence?

Coding interviews can be sometimes brutal and make you doubt yourself. After going through months of preparation practicing your data structures & algorithms, it can be a heartbreaking experience failing to crack the coding interview with your dream company.

When I was hunting for a full-time job during my Masters in CS from USC, I failed to crack several coding interviews before landing my job offer with Microsoft (and a few others). Despite having a decent prep, I managed to somehow mess up 1 or more of my coding interview questions.

While reading online, I bumped into some coding interview tips suggested by Gayle Laakmann McDowell (author of the must-have Cracking the Coding Interview book for coding interview preparation).

These 7 steps to approach coding interview questions are effective because cracking the coding interview is not just about your technical prep, but also:

  • listening skills
  • communication – ability to articulate your thought process
  • being meticulous – not rush and miss important details
  • staying critical towards your solution
  • picking interviewer hints – they usually try to guide you.

You will often want to skip a few steps below especially when you have already solved a similar question before during practice. That’s a classic mistake – do NOT jump steps!

Let’s get started by taking a simple interview problem to understand these 7 steps for cracking your next coding interview!

How will you find if an element exists in a list?

Step 1 – Understand the problem

Are you a good listener? If not, now is a good time to practice being one. Instead of jumping to the solution, listen to the question carefully and ask questions where necessary.

Do not make any assumptions! If you want to assume something, state it explicitly to the interviewer first.

ask-questions-during-coding-interview

For the problem in hand, you should ask questions like:

  • What kind of a list is it – array, linked list, etc?
  • What type of value can the list have – string, integer, object, etc?
  • Is the list sorted?

After getting your answers, let’s say the problem statement now becomes:

How will you find if an element exists in a 'sorted array' of 'integers'?

Step 2 – Use an example that is big enough (no special cases).

Come up with an example of the problem. Bigger examples with a simple happy path (without special cases) is usually better because it’s more intuitive to derive an algorithm for them as they give you more room to operate on. Try it out for yourself.

Good example: Find if 17 exists in array [-356, -23, -3, 1, 17, 19, 25, 56, 1050]
Bad example: Find if 0 exists in array [-1,0].

Step 3 – Find a brute force solution to the problem.

A brute force solution is easier to find, boosts your confidence, and keeps the conversation flowing. Always think out loud – do not murmur or think silently for a long time. The interviewer wants to know your thought process!

A simple solution to the problem would be to do a linear search and scan the array using a for or while loop. Return true if the element is found.

Now that you have a solution, do NOT start coding! State the time complexity of your solution which is O(n) in this case, where n is the number of elements in the array.

Start coding only if the time is running against you or the interviewer explicitly asks you to!

Step 4 – Optimize the solution!

Brute-force solution is a good starting point but usually not enough to crack the coding interview. This is the challenging part of the interview where you have to think of ways to reduce the time complexity and make your solution scale for larger data sets! So, tell the interviewer..

Let me think if I can do better!

Here are some tips that come in handy when trying to find an optimal solution:

  • Use hashmaps to make a time vs space tradeoff.
  • Save compute time by removing redundant/duplicate work.
  • sorted” is usually a signal to use binary search.
  • Try to map the question to a simpler version of a problem that you already know.
  • Try to put the question in a topic bucket – string manipulation, search, divide and conquer, DP, recursion, and so on.
optimize your solution
Flatten the curve!

As the array is sorted, we can use binary search which runs in log(n) time complexity.

Step 5 – Run through your solution in detail.

Hold on Speedy! Do not rush to coding yet. Figure out every minute detail – how will your algorithm work on the example in step 2, think of edge cases, the new time complexity, and so on.

The idea is to not rush into something that does not work and you end up wasting a whole lot of time – write a quick pseudo-code if that helps.

Do not rush during coding interview
You need to be quick but not rash.

Since we can't search a list in constant time, log(n) is the best that can be achieved.

Step 6 – Write Clean Code!

By now, you should have probably noticed that silent approval from the interviewer if you are headed in the correct direction.

You can now code the solution in the programming language of your choice – Do NOT write pseudo code complaining that there’s not enough space on the whiteboard!

Talk is cheap. Show me the code.

Linus Torvalds

Cracking the coding interview also tests how ready you are to write industry-standard code. You can score brownie points by writing clean code – use functions, classes, verbose variable names, naming convention, formatting, etc. So, don’t miss the chance to impress the interviewer unless you are running out of time.

If possible, talk through your code while whiteboarding the solution. Don’t go mute for 10 minutes – Code out loud!

> code binary-search

Step 7 – Test Your Code.

Good developers will always test their code!

Don’t just assume that the solution, which you just wrote under some interview nerve, will successfully do what’s expected. So scan the code one line at a time (more like an interpreter than a compiler) and squash the bugs!

coding interview tips - squash the bugs
Not running test cases can seriously jeopardize your interview!

Once you have scanned your code for correctness, dry run it against a small example followed by edge cases. If a test doesn’t work, run through your code again one line at a time against that test input and fix it.


For these 7 steps to work, it goes without saying that you should have completed the bare minimum DS/Algo preparation required for the coding interviews.

Note: If you already know the solution to a coding interview question, you will still want to play along these steps to give the impression that you are coming up with a solution on the spot. Or, you can be bold like I once did by telling the interviewer that I have seen the problem before and they changed it for me (brownie points – I did get hired later). So, I will let you choose.

Practice Tips To Crack The Coding Interview

Knowing the steps is not quite enough. From understanding the problem to finding an optimized solution, coding, and finally testing your code – there’s a lot that needs to be done with the ticking clock. So, you need to practice and embed these steps in your approach to solve every coding interview question henceforth.

Knowledge is of no value unless you put it into practice.

Anton Chekhov

Time your solution

A coding interview in a top-tier tech company typically runs for 45 minutes where you are expected to solve 1 medium/hard difficulty coding problem or 2 easy/medium ones.

Use a count-down timer to simulate the interview time pressure. You might initially struggle to finish these 7 steps within the time limit but trust me the mind adapts as you practice.

coding interview tips - time your solution

Get used to a white-board

The real interview will most likely be on a whiteboard. So, stop practicing on an IDE with auto-completion and other smart features.

While you can practice on a text editor like Notepad or simply a piece of paper, the closest experience would be to arrange a white-board. If you are in college, you can easily find one in study rooms or lecture halls. Otherwise, you can always buy one – whiteboarding is also a nice way to collect your random thoughts.

practice on a whiteboard

Do mock interviews

Before the actual interview, it really helps to get a perspective from another person who can monitor you. Mock interviews are an excellent way to perfect your interviewing skills including the 7 steps above. You can ask your peers or use a tool like Pramp.


Coding interviews can be daunting and often more so because one does not have a plan of action. Now that you know these steps, your next step is to put them into practice every time you solve a coding interview question.

If this article resonates with you, share it with your friends and peers – you grow when everyone around you grows!

If you have any questions or feedback, let me know about it in the comments below!

Also Read: How To Write A Killer Software Engineer Resume

Subscribe To Newsletter

Stay tuned to new posts from Ankur’s blog!

About Author

Hi there! My day job converts coffee into software, and I love it. I’m an outgoing person who likes meeting new people and making new friends. Lately, I have been taking a stab at photography and playing guitar. Traveling to new places excites me and I usually plan my trips months in advance.

11 Comments

  • Ankit Khemani
    May 29, 2020 at 12:05 am

    This is a brilliant strategy to tackle algorithmic questions in a coding interview. I totally agree with the fact that the mind adapts these 7 steps within the stipulated time limit in an interview as you keep practicing. It’s an iterative process and you only get better at it. Not only this help you in cracking the coding interview but also creates a good impression in an interview. Brilliant effort by putting these pointers together. I’m pretty sure that this post will be helpful to lot of people out there.

    Reply
  • Ronnie E.
    May 29, 2020 at 6:26 am

    I’m a software engineer and yes, coding interviews are BRUTAL. It’s so hard to prepare for it because you can never really know what they will ask. I’ve had some really challenging questions in the past that I’m sure I failed miserably. This is a helpful guide for the next interview coming up!

    Reply
    • Ankur Khemani
      May 30, 2020 at 8:27 pm

      Hopefully you cruise through your next coding interviews!

      Reply
  • Brianne
    May 29, 2020 at 12:20 pm

    These are excellent tips. You want to show off your skills when you have an interview, but you also want to be real about things. This is going to help a lot of people.

    Reply
  • Celeste Engelbrecht
    May 30, 2020 at 6:17 am

    Fantastic read. Highly recommended to anyone breaking into the coding industry. I’m not a coder myself but have dabbled in it.

    Reply
  • Warp Speed Odyssey
    May 30, 2020 at 8:48 am

    Those were great tips for a interview in coding interviews.

    Reply
  • Gervin Khan
    May 31, 2020 at 6:14 am

    These are definitely a great and helpful tips to follow by someone’s who will undergo for a coding interview. Thanks for sharing!

    Reply
  • Subhashish Roy
    May 31, 2020 at 7:37 am

    Although I am not a software engineer myself I have done sessions with many of them on interview facing skills. They were essentially aspiring management graduates from BITS,Pilani where I also completed my education. But this was some great learning for me on coding. Some topics are essentially same like listening skills, communication and being meticulous.

    Reply
  • Elisha Fernandez
    May 31, 2020 at 11:59 am

    Interviews are about coming off as personable, yet professional. These are excellent tips.

    Reply

Let us know what you think

shares