Chapter 6. Computer Science
For coding questions, the best way to prepare is to write code every day. Programming mastery requires consistent practice.
However, the type of coding you do every day is different from the type of coding asked during interviews, so it’s a good idea to get some practice. Before your interviews, do a few typical software engineering questions to get yourself into the problem-solving, whiteboard coding mode.
If you haven’t seen them in a while, pick up a good book on algorithms and data structures and skim it. We recommend the book Data Structures and Algorithms in Python by Michael T. Goodrich and the classic Introduction to Algorithms by Thomas Cormen et al.
We also recommend practicing websites such as LeetCode, CodeSignal, and HackerRank. Those sites rank problems by difficulty -- you should try to solve medium and hard problems. Most of them have solutions available in case you want to compare your solutions to more optimal ones1.
This chapter addresses the three major aspects of computer science that are covered in machine learning interviews: algorithms, complexity and numerical analysis, and data, which includes data structures.
🌳 What programming language to use during interviews 🌳
If you're comfortable with only one language, feel no qualms using it during interviews. If you're comfortable with multiple languages, listen to the question first before choosing a language. It shows that you understand that different languages are built for different purposes: a language suitable for one task might not be optimal for another.
Put all the languages you know on your resume but don't feel the need to show them off during interviewers. Employers would rather hire someone really good at one language -- it means that you can learn to be good at other languages -- than hiring someone mediocre at multiple languages.
Based on the language you choose, interviewers might infer what you're interested in. For example, a hiring manager told me that if a candidate chooses to implement data structures in Python, he knows that this candidate doesn't focus on performance.
Python has become the de facto lingua franca of machine learning -- most frameworks have Python APIs and most open-source projects are written in Python. It's a useful language to know and most interviewers probably expect it, but don't feel like you have to use it during interviews. If you're more comfortable with another language, use it. Writing a complex model in another language, say Swift, is a lot more impressive and helps you stand out.
It also helps if you know at least one performance-oriented language such as C++ or Go. C++ is more popular with more support, but Go is easier to learn and manage. Since more and more machine learning models are being served as web applications, many startups look for machine learning engineers with front-end skills. Fluency in TypeScript or React is a huge plus.
1: When I was preparing for interviews, I practiced some common algorithm and data structure interview questions and pushed their solutions to GitHub at: https://github.com/chiphuyen/coding-exercises.