For most programmers, solving coding interview problems is not a natural way of coding. It takes time and practice to get good at them. Using spaced repetition techniques makes this practice time more effective.
The canonical example of spaced repetition is using flashcards to learn language vocabulary. Anki is a popular software application that implements spaced repetition by presenting each flashcard at the optimal time. In vocabulary study, each card is fairly short, just a single word and definition. But there are many cards to learn, since learners need to know thousands of words to become fluent in a language.
For coding interview problems, the quantities and material to learn are quite different. The well-known Blind 75 list, as its name implies, has only 75 model LeetCode problems. Even the largest list on NeetCode has only 327 problems. Each of these problems might require 25-50 lines of code to solve. That’s small by real-world programming standards, but there’s a lot of detail packed into those lines.
Algorithm implementation is a different kind of knowledge than vocabulary definitions. You wouldn’t want to memorize how to implement binary search the way you learn what a word means. Given these differences, you might wonder how applicable spaced repetition is to LeetCode problems. Maybe it’s better to solve a problem once, write a detailed model solution to make sure you understand all the details, and then move on to a new problem.
The problem with this approach is that if you only solve a problem once, you’ll never practice recalling the details of the solution from memory, which means you probably won’t remember how to solve it. Although they represent different types of learning, a complex activity like implementing an algorithm and a simpler activity like defining a vocabulary word both use the brain’s long-term memory functions. Rather than having to re-discover the principles of binary search when you need that algorithm, you can instead remember your model solution. That frees up more of your 30-minute interview to adjust your implementation to the specific problem you need it for.
To make this more concrete: If you want to remember how to implement binary search in a year, it’s not enough to practice once today and again after a year. Instead, start out with small intervals and increase them with each repetition. The basic interval is one full day (since sleep is important for consolidating learning). So when you’re learning a new model solution, start by practicing it every day for a few days. Once that becomes easy, a rule of thumb is to double the time interval after each successful practice session: Two days, four days, eight days, and so on. Adjust the interval times based on how hard a repetition is. If you’re using an eight-day interval and the problem seems very easy, try skipping 16 days and go directly to 32. If it’s too hard, stay at the same interval or cut it in half. Once you get to 256 days, you have probably learned the problem for the purpose of interviewing. You can either remove it from your model problem list to make room for another problem, or just practice it once a year to make sure you still know it.
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.