Irine's coding interview guide

Irine's guide for preparing for coding interviews at large tech companies like Google, Facebook, Amazon, and Microsoft.

About the author

Irine Karatsapova is known to many Russian-speakers as one of the leaders of the SNS Internships Telegram group. It is maybe the most popular online group in the region on the topic of software engineering jobs abroad.

As a university student in Russia Irine applied to many tens of companies and managed to get multiple internship and full-time offers abroad. She ended up interning at Google twice, at Amazon, and at Jane Street. In addition to that, she got some full-time offers including the ones from Amazon, Google, Microsoft which she declined to try more internships.

Introduction

First of all, let’s decide how motivated you are. There are two ways: 1. You don’t want to spend time on preparation. 2. You are ready to work hard.

1. You don’t want to spend time on preparation

Probably you are comfortable where you are. Probably you think that it would be nice to move abroad to work at one of those greatest tech companies like Google or Facebook. But, of course, not now.. probably in 1-3 years.

Congratulations, you are not motivated :) But what is more important, you do not care if you will be rejected this year [and that is awesome!].

If you want to make the life of future “you” easier, take the list of 50 top tech companies and apply to all of them. Now. Without any additional preparation [remember... we agreed that you do not care about failures; I try my best to optimize your value while minimizing your efforts].

You will be pretty lucky to pass screening in 2-5 companies. [The screening part is pretty random due to an enormous number of applications, thus the percentage of companies inviting a candidate to an interview rarely exceeds 10%. It is the same for all of us, nothing personal. And that is the reason to apply to 50 companies].

Ok, an interview. First of all, it is just fun [try to enjoy this wonderful mental exercise!]. Secondly, you will have an opportunity to feel what it is like to have interviews at the top tech companies [there are many guides describing it, but it is always better to feel yourself]. Future “you” will give you many thanks for those insights when you return to the process more seriously in a year or in several years.

As a side bonus, it may happen that you do pass interviews. Well done!

First of all:

— you did not spend any extra time for preparation and probably don’t need that much of preparation in the future

— you became much more confident in yourself, so you won’t worry next time [and you did not worry this time, because you did not really care about the result; remember, you are comfortable at your current job]

Secondly, now you can:

— change your mind and decide to actually join the company where you received an offer

— ask the company to postpone the offer for several months or a year as you need to finish your current project [it works]

— negotiate the salary at your current company and stay there

There were no negative effects by now :) Moreover there are none even if you did not pass interviews. It is always possible to apply again in a year. Sometimes companies will even remind you themselves that probably it is time to try one more time. And remember, you understood how it works and how far away you are from passing the interviews successfully [you will be much less frustrated and more satisfied in the future].

2. You are ready to work hard

Ok, finally we move to the situation where you are motivated and ready to spend time on preparation in order to receive an offer at the company of your dream instead of a random company.

Have you ever heard about algorithms and data structures? If not, most likely you want to start with the course giving you the theoretic basis. For instance, Intro to Algorithms and Data Structures from Google.

Additionally consider reading Cracking the Coding Interview. Probably you would like to skip coding problems and solutions [you will cover it later], but the theoretical part is pretty useful there.

Finally, let’s move on to practice. LeetCode is a wonderful site containing more than a thousand coding problems.

[Of course, there are many other options like HackerRank, Interviewbit, etc. If you have strong preferences for any of them, go for it, though the next paragraphs are based on LeetCode. Additionally, I would like to mention that Codeforces or Topcoder is an overkill, you don’t have to be good in competitive programming to pass interviews successfully].

Tl;dr on using LeetCode:

— Just solve many-many problems (random ones, easy and medium level) — Dive deep into problematic topics (theory + practice) — Run through the solved problems one more time before the interviews

Let’s have a look at the LeetCode a bit closer.

  • First steps:

    • Initially, you may be slightly overwhelmed by the number of coding problems. I would suggest starting with the easiest tasks and gradually increase the difficulty.

    • Here is the wonderful list of sorted problems and here is the explanation, how the order was formed [I enjoy the “Score” section, though please be more relaxed about the approach in general].

    • You can ignore tasks marked as “Premium” [if you don’t have one] and “Sql” [you won’t see those tasks in interviews].

    • Additionally I would recommend starting with the problems that have the section “Solution” for it, not all of them have.

  • How-to approach the problem:

    • Read the task, come up with a solution [it may take time] and write down the implementation [it may be obvious, but I have to mention this step].

    • Think about corner cases and add custom tests to check them before submission. [Later your interviewer will look for it. Plus in general, no one will come up with tests for you in real life.. and it’s a bad idea to test your code against reality, that is why spaceships fall].

    • Submit. Fix bugs until you pass all tests [but of course try to avoid bugs during the previous step].

    • Think about time and memory complexity.

      • First of all, you should be able to estimate time and memory complexity.

      • Also try to figure out whether your solution is the most optimal [Are there any repetitive or unnecessary steps? Are there any reasons why current time complexity can’t be improved? For instance, if we have to look at every element of the array, it can’t be better than O(n)].

      • Rewrite your code if needed. Try to avoid similarly unnecessary and sub-optimal steps in future tasks. There is nothing bad in writing code iteratively, but it is still useful to learn from the previous mistakes and save your time.

    • Read the section “Solution”. Compare your approach with the proposed one. If you found out that there is a better solution, implement it [without peeping at the “Solution” section].

    • If there is no “Solution”, go to the “Discuss” page, sort it by “Most votes” and find several solutions there [probably you prefer the same programming language as the one you used].

  • If you had a hard time solving the problem:

    • First of all, make sure that you spent enough time thinking about the possible approaches [it is bad if you take hints and immediately understand “oh, that was obvious!”; just think harder next time, you are not in a rush]. However, if you were not able to solve the problem, open the hints one by one, then read the solution. Implement the solution.

    • Probably you will understand that it won't be that easy to solve a similar problem. Look at the Related Topics section. Repeat the related theory and practice several more tasks on that topic.

    • Then come back to the random tasks [without the topics known in advance].

  • As solving tasks becomes easy:

    • Increase the difficulty of your tasks. If you go through the list given above, you can skip some of the tasks to increase the difficulty more rapidly.

    • Later you can use the button “Pick one” to receive a random problem. Ignore “Hard” tasks, most likely you won’t meet them at the interview.

    • Eventually you understand that it is pretty easy for you to implement your approach, you just need to think up a solution. Now you can start solving the tasks in your mind, without writing down the solution. It is pretty convenient if you don’t have your computer with you [i.e., while in transport or hanging out with friends]. And it is really fun, learn to enjoy the process! However, do not get carried away and still practice implementation while at home.

  • When to stop:

    • I don’t know how many tasks you have to solve: 100, 200, 500, … . At some moment of time you will feel that it became super easy, that you always come up with the most optimal solution in the first seconds and accurately implement it several minutes. Ok, probably you are ready :)

  • Before the interview:

    • Probably you would like to repeat what you solved during many weeks of preparation. Read the task, quickly come up with the optimal solution, and look through your submission.

    • You will be able to cover a lot of tasks in a short period of time. You will remember the different approaches which you implemented. You will become more confident.

Another important step of preparation is mock interviews.

Here you will be able to practice not only hard skills but also soft skills which are important during the interview:

  • The standard order of solving the task:

    • The interviewer describes the task to you.

    • Ask questions to clarify the conditions if necessary.

    • Describe your approach(es) stating the time complexity [and memory, if the interviewer cares].

    • Write down the implementation.

    • Test the code.

    • State the time and memory complexity again.

    • Probably make several iterations improving the current approach or adopting your solution to the new conditions given by the interviewer.

  • Remember to express all your thoughts out loud:

    • Your interviewer becomes frustrated if they do not understand what and why you are doing. They are not very good at reading your mind. Make their life easier, expressing all your thoughts, plans, and steps of implementation out loud.

    • As soon as you think you fully understood the task, start describing how you can approach it [you don’t have time to think about it, sorry]. Probably you did not come up with the most optimal solution at once. Ok, describe what you have by now. You still have some time to think up a better solution while describing the more obvious one.

    • If you feel that there is a better solution, but you don’t know it yet, say it: “Currently the time complexity is O(n^2). I think we can do O(n*logn), but I would like to implement O(n^2) at first and improve it later. Is it ok for you?”.

      • If your interviewer wants O(n*logn), they will say “no” and give you hints, but most likely they will allow you to implement O(n^2), giving you more time to come up with the better solution [do not forget to think about it while writing down the implementation].

      • For advanced users. Sometimes [though pretty rarely] I articulate several approaches to the problem and then start implementing the medium one instead of the best one. I just know that in this exact case I will spend too much time on the best solution. It is better to finish and test the code for the medium approach than to be confused with the best one. At the same time I did show to the interviewer that I know the idea of the optimal algorithm.

    • While writing down the implementation, do not be silent. Every line of code has some meaning, articulate that meaning.

    • If you want to skip corner cases at first, say it, showing that you did not forget about them.

    • Concerning the time and memory complexity, do not forget to mention them.

  • Tests:

    • It is extremely important to test your code. And it should not be five minutes of silence + “I finished testing! It works”. Write down your test cases and go through your code, line by line.

    • And… one last reminder, please, do not forget about corner cases [it is really important, both during the interview and in real life].

  • Other hints:

    • Pretend that you have helper functions which may be hard or boring to implement [i.e., binary search if that is not the main idea of your task]. Most likely the interviewer won’t be interested in that part or they will remind you to implement it later.

    • As a follow-up to the previous point, if you do not remember the name of the function, method or module, name it somehow [more or less self-expressive] and use it. [For instance, I know that in python there is a module with functions “combinations”, “permutations”, and so on, but I never remember that it is named “itertools”. Similarly I suffer when I have to remember how I add an element to a queue: q.add? q.put? q.append? It is annoying thus I just randomly choose one of the options and pretend that it is true].

    • Illustrate all your words where possible. Give examples and write them down while describing your approach. Test your code highlighting the line you are currently at and writing down the current state in the comments. Additionally, learn how to draw graphs in a Google Doc [otherwise it may be hard to talk about them].

    • Your interviewer is your friend, listen to their hints, they want to help you.

Good job! You are ready. Now it is time to apply for several dozens of companies :)

Why so many? You will feel more confident at the company of your dream if you already successfully passed the interviews in the other companies, which you do not really want to join. And anyways it is always better to have a choice between several offers [additionally it will help you to negotiate your salary].

Good luck! I am sure that everything works out. You will be successful during the interviews and satisfied with your new job :)

Irine