A common criticism of algorithmic coding interviews is that they select for people who have “memorized a bunch of obscure algorithms.” In this view, recent computer science graduates have an advantage over experienced developers because they can still remember the material from their algorithms courses. And candidates can beat the system by memorizing a list of solutions and brain dumping the appropriate solution for the interviewer.
This way of thinking about coding interviews doesn’t make much sense once you have some experience with the process. Although interview problems may be difficult, the algorithms they require are hardly obscure. Algorithms that use hash tables, binary trees, and breadth-first search are commonly taught to undergraduates. But these basic principles can be combined in infinite variations, so memorizing solutions isn’t a very helpful approach. As for recent graduates, they may have some advantage. But given the low pass rate for entry-level interviews, it’s clear that having taken an algorithms course in the past few years is hardly a silver bullet for coding interview success. Most candidates at any level of experience have to prepare for interviews, beyond what they do in their daily work.
The grain of truth in this view of coding interviews is that interviews are not a pure intelligence test. They require domain knowledge, not just problem-solving skills. It’s possible to work as a programmer without ever studying algorithms. In fact, it’s even possible to work as a programmer without remembering programming language syntax or libraries. You can always look things up on the fly in the documentation or Stack Overflow, or have a chatbot write code for you. But you can’t pass a coding interview this way (at least the in-person variety). So for coding interviews, and efficient real-world coding, you do have to remember some information. It’s not enough just to understand concepts.
Since we can’t just memorize all the solutions, but we also don’t have time to figure everything out from first principles during the interview, we need a more nuanced approach to learning this material. Fortunately, we have already covered the necessary tools in previous tips. The key is to maintain the right balance between remembering and understanding.
To do this, we have to use the spaced repetition process correctly, in particular when it comes to interval lengths. Although you must set intervals lengths according to certain heuristics to make the process work, there’s also a risk that interval practice will push you towards memorizing a solution. In the early repetitions of a solution, you have to remember a few things: the general approach that a problem requires, the details of an algorithm, and any language syntax or libraries that you don’t already know from other problems. This type of remembering is good. It’s exactly why repetition is a good way to improve your skills. Repeating the solution with short intervals shows you what you need to learn.
The problem occurs when you try to move beyond short intervals and you get stuck. According to the spaced repetition process, when you have trouble solving a problem, the correct approach is to shorten your practice interval and try again. This may in fact be necessary. But as you think about the right interval to use, make sure you’re not using repetition as an alternative to understanding. Repetitions are good for identifying areas you don’t understand yet, and for reinforcing things you already know, but they’re not good for learning things in the first place. To do that, you need to go back to your model solution, identify the gaps in your understanding, and do the research or experimentation required to fill them. Only after you finish that process does it make sense to go back to repetition.
This year, I’m publishing a series of tips for effective LeetCode practice. To read the tips in order, start with A Project for 2023.