4 - Coding Interview

Authors: Stefano Ivancich

HOW TO PREPARE FOR CODING INTERVIEWS

Use LEETCODE.
WHY LEETCODE IS BETTER than other (free) platforms (as 2024):

  • Problems were almost all asked in real interviews. No competitive programming o theoretical problems.
  • Most of the problems have fully explained solutions.
  • For each problem there is a well-organized sub-section with a very active community.
  • Hackerrank, codility, … have too long problem statements or don’t have clear solutions.
  • Codeforces, Codechef, kattis, … are for competitive programming.
  • Most of the problems (probably all) on books like CTCI and EPI are on Leetcode. (Use those books just to learn the theory, don’t waste time on doing problem on paper, search them on leetcode)

Leetcode alternatives:

  • Hackerrank (used also for online assessment, contains also other programming topics)
  • Codesignal (used also for online assessment)
  • Codility (used also for online assessment)
  • HireVue (used for online assessment)
  • Codingninjas (dsa guided path, mock interview, competitive programming)
  • CodeForces (Competitive programming)
  • Kattis (Competitive programming)
  • UsacoGuide (Competitive programming)

How to prepare:

  • Read the first 86 pages of CTCI that explains how interviews works.
  • Watch a couple of videos on YouTube “Google coding interview” to get familiar with the context of coding interviews. (Do not watch too old videos, the interviews slightly change over time). Example
  • For each chapter of CTCI read the 2-3 theory pages (or theory here) then do exercises on the respective leetcode.com/explore/learn/ section. The optimal topic order for study should be this: Array, Hash table, Linked List, Stack & Queue, N-Trees, Binary Tree, Binary search trees, Trie, Heaps, Sorting, Searching, Recursion 1, Divide and Conquer (Recursion 2), Backtracking (Recursion 2), Dynamic Programming, Greedy, Graphs, Bit Manipulation, Math problems (combinations, permutation, prime numbers, probability, …). You can also use the order proposed in neetcode.io/roadmap
  • Then do problems on the problem sets (Grind75, Easy, Medium, Hard, Blind75, Google, …).
  • Do mock interviews (pramp.com)
  • (Optional) Learn more theory on books: Goodrich (in Python, Java or C++), Competitive Programming Handbook, Cormen, CP4.
  • If you want to spend money for the theory (is not really needed), we suggest the following courses: Leetcode DS&A crash course, Neetcode DSA for beginners, Neetcode Advanced

General advices:

  • Do problems on topics that you struggle at. Is not useful to do problems on topics you are already good.
  • Do problems slightly above your level.
  • Be constant: Solve at least ONE problem a day. (Do something like Leetcode Daily challenge)
  • If a problem has too many dislikes, carefully read the problem statement and comments before solving it to avoid wasting time in useless or too harsh problem.
  • Once you solved the problem, look at the discussion section and read other people solutions.
  • Easy problems often are too easy. On the long run try to solve mostly mediums and hard.
  • Use a timer. Leetcode has an embedded timer.
  • Do problems on the interview lists of the company you want to join more than once.
  • Participate in Leetcode contests to become comfortable solving problems under pressure.
  • Do a mock interview AT LEAST once a week and recreate as much as possible the interview environment (clothing, light, papers, materials, whiteboard, …) to become comfortable.
  • Use just 1 or 2 platforms to prepare, otherwise you will end up doing all easy problems in a platform, change to another platform, do all the easy problems, then switch again and so on. You will end up doing just easy problems. Do a couple of problems on other platforms just to become comfortable with the platform that is going to be used for online assessment (e.g. hackerrank, codility, Codesignal) and interviews (e.g. hirevue, coderpad).
  • Write down the most interesting problems and techniques that you encounter. In general, medium problems are a composition of easy problems/techniques and hard problems are composition of medium problems/techniques.
  • Do yourself a favor and take notes of the topics you are studying. During this time, you will be covering so many different subjects and tricks, and being a human being guarantees that you will forget the majority of them, so take notes and review them once in a while. Your notes are also a valuable resource for the next time that you are preparing for the interviews.

If you cannot solve a problem:

  • Spend no more than 20-30 minutes without making progress. Just go look up the answer. Contrary to popular belief, most struggling past 30 minutes is pointless.
  • Read just a little part of the solution and try to go on yourself. If you struggle, read a little bit more and so on, until you really cannot solve yourself.
  • Always implement it yourself, don’t just read the solution and copy and paste the code.
  • Always mark it as something you need to try again. Wait at least a day and try to solve it fresh. If you fail, repeat at infinitum.

Aim to solve:

  • 60 Easy problems (<10min)
  • 100 Medium problems (<15min)
  • 40 Hard problems (<25min)
  • Ratio 3:5:2 (easy:medium:hard)

Important Problem Sets:

Other problem sets:

Mock Interviews:

Overview of a Coding Interview

This is a mental framework we suggest to follow when interviewing - it is not meant to be 100% accurate. alt text

  • Short Introduction (5 min): Just introduce yourself! What’s your name, your education, current job position, why are you interviewing, …
  • Technical Assessment (45 min): The real stuff!, you will get a coding problem by a trained interviewer
  • Closing questions (5 min): Closing remarks, always have a question prepared for your interviewer (How is working for company-X? What’s the thing you enjoy the most about company-X? How is the food at company-X’s canteen? …)

Technical Assessment Timeline

alt text

  • Problem Analysis (5 min): You just have been given the coding question. Make sure you understood the question: it is your responsibility to identify the requirements and agree on a set of assumptions together with the interviewer; don’t work on your own, hidden assumptions.
  • (Iterative) Design Phase (10 min): Work together with the interviewer towards a solution. Start from the naive solution and work your way towards the optimal solution by identifying (and communicating to the interviewer) the bottlenecks. Use time and space complexity analysis to justify your design choices/changes. Don’t be afraid to ask question; avoid random guessing or focusing on irrelevant stuffs!!
  • Coding Phase (15 min): After you agreed together with the interviewer on a design choice, it is time to code it!. Always Tell what you are typing in and why.
  • Testing & Bug fixing (5 min): Be able to proof-read your code to find bugs without running the code. Dry run your code (by hand!) with some example inputs and outputs.

STUDY PLANS:

THEORY (WEBSITES):

THEORY (BOOKS)

THEORY (VIDEO)

PRACTICAL:

COMMUNITY-MADE

[*] Recommended!