Coming from a mathematics background with limited academic coding training, I discovered that internships at companies that I was interested in relied on coding interviews for recruitement, including for research positions during my PhD.
Although I code a significant part of the day for my research, preparing for the coding interviews is an entirely different, and very specific exercise.
While preparing for coding interviews, I kept notes of useful (to me!): resources, comments and code snippets.
I successfully passed the interviews for Google and Facebook internships 4 months appart, and I found myself giving advice to other PhD students about how to prepare for coding interviews.
A targetted search will show that there are a lot of great resources for preparing the coding interviews ! This is a collection of resources that I subectively found useful.
For the Google interviews I had roughly the following preparation:
- 1/2 days of finding good resources
- ~5 weeks during which I practiced for ~1h-1h30 every morning and 3-5 hours per day on weekends
I did not start from zero:
Before preparing for the Google interviews (2 years before) I had read a part of Cracking the Coding Interview, the whole introduction, and at several exercises (with solutions) per chapter.
This means I was already at least somewhat familiar with most basic data structures (lists, linked-lists, stacks, trees, ...).
- Whenever I stumbled on concepts/algorithms (trees, dynamic programming, ...) I wasn't familiar with, I would google and read about it.
- Typically I would end up on a Geeks for Geeks page which I would read
- I would then rewrite the proposed algorithm, and check that it actually works (through LeetCode or custom test cases)
- For an overview of more complex algorithms I found the videos by Abdul Bari very pedagogical and clear
- especially on Dijkstra, QuickSort analysis, Prims and Kruskals, Disjoint Sets data structures
- Geeks for Geeks top 10 algorithms in interview questions
- I cycled through questions for each chapter, to make sure I had a similar coverage of all the topics
- LeetCode
- I payed for the Premium account, and sorted the questions by frequency for the company I was targetting
- I did maybe ~30% easy, 60% medium, 10% hard questions, and would stop when the code would pass the tests
- Given that for Google you are coding in a Google doc, I would read the question in LeetCode, then write the code in a GDoc, and then copy-paste the code in LeetCode to pass it through the tests
- Leetcode also has a mock interview mode that is timed and provides a set of 2/3 questions which I found useful because it is closer to the real interview setting (you don't know in advance if the question is hard or not, which I find is an important prior knowldege which you don't get during the real interview, and a timer)
- I would try to solve them in real-conditions, including often speaking to an imaginary interviewer aloud in front of my computer (talking and solving the problem at the same time required some practice)
- I did not solve problems from Cracking the Coding Interview at this time, but I did go through my notes on the exercises I had solved previously to refresh my memory on these classical exercises
- I also liked the following list from the Tech Interview Handbook although I didn't follow their suggested exercise list
- One of the best advices I got was to go through Google's python styleguide, which is a great reminder on good coding practices and edge cases of python (some personal notes on this)