Hacking the Coding/Machine Learning Interview: Tips Beyond “CTCI” :)
Disclaimer: I am a software engineer / research scientist at Facebook for Search Ranking. As a consequence, there may be hints of Facebook sprinkled throughout this blog series. However, I should note that this blog series is not sponsored by Facebook, and represent my opinions only, and not those of the company.
Several friends have asked me in the past for advice on preparing for software interviews at tech companies like Facebook and Google. I typically share with them a collection of tips and resources to give them a sense of the technical bar that is expected of them. I wanted to share the same tips and resources here for readers 🙂
How this might be helpful for you
I learned software engineering nearly from scratch, without a computer science / software engineering degree. However, I had a few fundamentals to guide me — notably that I come from an engineering background, and that I love working with data. I wrote up these tips and resources as if I were writing them for myself.
This is also not a giant book on algorithms or data structures. This study guide is simply a compiled list of resources, with pointers to guide you along the way.
How is this different from Gayle Laakmann McDowell’s Cracking the Coding Interview?
The post title is a playful reference to what is probably the bible for software interview prep, but this post is hardly book-length. This is just a collection of links with some guidance on how to leverage each resource 🙂 I recommend you use this as a guide to inform your study plan.
Here goes 🙂
Interview Prep Strategy Overview
There are a few simple steps on preparing for technical interviews:
- Read (but skim if you have to). Reading up on basics will give you a sense of what you have available at your disposal when solving problems. If you don’t come from a software engineering academic background, it can be confusing to know what books to pick up / websites to scour. I’ll detail them here.
- Practice. I strongly encourage that you spend the most time here, this is really the #1 piece of advice for technical interview prep. You need to be able to quickly understand a problem, come up with solutions, code them up, test them, and understand their algorithmic complexity. The bottleneck here is usually finding good resources. I’ll cover that here too 🙂
- Talk/Write. Knowing how to solve problems is half the battle in a technical interview. You’ll definitely be evaluated on your ability to ask clarifying questions, give high-level explanations of your solutions, and test your work. To do well here, you need to practice talking and writing out your solutions by hand. Talk to yourself and record yourself or find a buddy. I won’t cover this step as much in this guide, but let me know in the comments below if you’d find a separate post about this useful 🙂
- Repeat steps #2-3 as needed. As you work your way through the industry you might find that you will need to brush up again on interview problems. You may have a decent working knowledge of the fundamentals, so I would recommend focusing more on practicing and talking/writing.
I’ll list out some resources below to get you started on how to practice and what to read.
How to Practice
The most important practice resources
- Do as many problems as you can on LeetCode. As you might know, this is probably the definitive resource for practice interview questions. I would recommend purchasing the Premium account for a few months or a year since this allows you to filter by company and frequency. I suggest going through all Easy + Medium for a company, then grinding as much as you can through all Hard questions. Pro tip: Whenever you are stuck or have just finished a problem, go through the discussion section for the problem to get some tips or understand the “optimal” solutions available. The community on LeetCode provides amazing advice; utilize it 🙂
- Learn how to tackle system interview problems on InterviewBit. This is especially important for experienced candidates — if you want to land a higher-than-entry level job at a tech company, you probably need to know how to design software systems.
- Source through more company-specific questions on CareerCup. While I do not like the quality of the questions/discussions as much as I do from InterviewBit, I have many times found eerily similar “common” interview questions asked. It helps if you sort these questions by company then by popularity.
More Practice Tips
- I think the biggest “bang for your buck” kinds of algorithms questions universally across tech companies are going to be in applying tree and graph traversal. Obvious items include Depth-First Search (DFS) and Breadth-First-Search (BFS) traversals, but you might be surprised how many times topological sort has saved me.
- As an exercise, I would also highly recommend you study Manacher’s Algorithm. I don’t think I’ve gotten questions quite this rigorous, but reasoning about it was a very useful exercise for me. Here’s one decent resource on the subject.
- While likely fallen largely out of style at this point, raindrops and walls is a really fantastic problem that I think is worth studying. I can’t find the original blog post anymore, but here’s Business Insider on the matter: http://www.businessinsider.com/twitter-job-interview-question-rainfall-walls-2013-12
- In general, if you’re looking to practice “how to design <famous system>” type questions, I would suggest Googling it. There might be a research publication that touches on the system components at least from a high level 🙂
What to Read
It’s important to get a general feel of what “tools” you will need to succeed.
A word of warning: Some of these topics can be extremely engaging, and you may end up diving deeper than you need for just interviews. If you are only here to prep for interviews, then I recommend using these resources only to review basic concepts. The only exception to this warning is Cracking the Coding Interview, which I would highly recommend reading front-to-back 🙂
The one book you absolutely need to read (and you might have probably heard of by now) is Cracking the Coding Interview (usually lovingly abbreviated as CTCI) by Gayle Laakmann McDowell. This book is recommended by pretty much every recruiter from large software companies, and it’s obvious why — Gayle is amazing at condensing tough textbook-heavy concepts from Computer Science into easy-to-understand explanations (covering both data structures and algorithms), and presents great practice questions to get you started. I’ve heard from friends that this is all they used to prep. Personally, I don’t think this is sufficient — I think you’ll want to practice a lot, especially if you don’t have particularly heavy experience in coding and algorithms.
Gayle is also pretty active on several public platforms, including Quora.
Brush up on your language of choice, including standard functions, object-oriented syntax, and some best practices. If you don’t yet have a language of choice, I suggest working with Python, C++, or Java. One call out — Python is probably the easiest to learn, though it can be tough to master. If you have zero preference on language, I would recommend starting there.
- C++: I learned C++ through LearnCPP and also CProgramming.com. I didn’t take it, but I also found a Code Academy class that looks promising, if you’re interested in an interactive environment. If you’re past the fundamentals, I also highly recommend Effective C++ (I wrote a quick blog post on this) and CPlusPlus’s reference on STL.
- Python: The official tutorial on Python can be found here. I also recommend surveying the Official Hitchhiker’s Guide to Python for more resources. Finally, two good interactive tutorials include LearnPython.org and CodeAcademy’s course for Python2 (Python3 is currently only available for Pro accounts)
Be careful diving too deep into languages. For example, in C++ you probably won’t need to go all out understanding templatization, lambdas or even pointers (though these all come in handy at work, and occasionally in interviews). In general, for interviews you will be able to get by knowing just a few concepts:
- Basic control structures: loops, switch/cases, exception handling, etc.
- Standard functions: Arithmetic, string handling, printing output, etc.
- Data types: Numbers, strings, pointers, etc.
- Available data structures: Arrays/vectors, sets, stacks, queues, maps
- Other important features: Classes, functions
If you want to learn more on algorithms, to ensure you’ve covered as much ground as possible, there are some amazing resources out there to learn.
- MIT OpenCourseWare’s Introduction to Algorithms. This is MIT’s official class on algorithms and is how I first learned everything I know about “algos”. I recommend going through all of the lecture videos if you can 😉
- Introduction to Algorithms, 3rd Edition (“CLRS”). This is the bible on algorithms for computer science students. It’s a hefty book, but it’s truly the definitive source on algorithms. Fun fact: Thomas H. Cormen, the first author, seems quite active on Quora 🙂
- Algorithms by Sanjoy Dasgupta. This is the first book I used to learn algorithms, back when I had no idea what an algorithm really was. It’s shorter than CLRS, and I think that was a good thing — I’m not sure I would have been able to finish CLRS on a first pass 🙂
- Codility. This is the website I used to first learn how to apply algorithms in preparation for interviews. They do an amazing job with their “lessons”, where they include nice explanations in PDF and include interactive practice problems. Codility also hosts fun challenges where you can compete for prizes.
Be careful going overboard with algorithms. In general, you probably want to be comfortable with a few basics:
- Sorting. Definitely at least bubble sort, merge sort, and quicksort
- Trees. You definitely need to understand breadth-/depth- first traversal. You might find topological sorts helpful 🙂 And it helps to know what a binary search tree is.
- Graphs (at least how to traverse them, and perhaps A*/Djikstra’s)
Let’s say you’re actually preparing for a machine learning interview. You’ll likely need the above tips to succeed on your coding interviews, but you’ll also want additional resources to build up your ML skills 🙂
- Machine Learning by Andrew Ng, on Coursera. This is the definitive course on getting up to speed in Machine Learning fundamentals and probably accounted for 80-90% of all of the ramp up I used for ML interviews.
- Rules of ML by Google. This document includes a great list of guidelines you might want to keep in consideration when designing ML systems.
- Unicorn: A System For Searching the Social Graph. I love this paper!! But I’m biased as I’m a software engineer at Facebook Search 😉 This is an amazing external publication about how Search at Facebook works.
- Under the Hood: Indexing and Ranking in Graph Search. This is another great article on search at Facebook 🙂
- DNNs for Youtube. I believe this is a rather famous paper in Machine Learning in general 🙂
- Deep and Wide Learning w/ TensorFlow. I think Deep and Wide Learning is a pretty cool application of DNNs, and is kind of intuitive to understand (at least the way the papers present it!). It’s also fun conversational material for other ML enthusiasts.
- How FB Newsfeed Works (2015): YouTube Video (45 minutes, describes technical bits)
- How does Facebook Newsfeed Ranking Work? An introductory 3 minute video that I think is meant for a much wider audience.
- Netflix Recommendations
Navigating Job Offers
I’ll probably write a separate post at some point about negotiating job offers (let me know in the comments if that would be helpful!), but for now I’ll share just a few resources.
- Paysa has surprisingly very good pay data, with personalized predictions for your next job/level. That said, I’ve heard a few reports that they may sometimes overestimate your compensation. Regardless, I think it’s a good dataset to get a sense of your market rate at a given company/role.
- Levels.fyi also has extremely good pay data, though it’s not exactly personalized. They provide useful visualizations that compare compensation for comparable levels across different companies.
Hope this helps! Please let me know what you think 🙂 Good luck and kick some butt in your interviews!
Leave a Reply