When you use spaced repetition for LeetCode practice, keeping track of repetition intervals on your own is better than having practice software do it for you. Unlike vocabulary words, LeetCode model problems and solutions are complex, so you’ll only have time to practice a few of them per day. This gives you the time to consider the appropriate interval length and what your goals are for the current repetition. Here are some suggestions for what to focus on at each interval length.
0 days
It helps to practice a model solution even right after you finish reading it. If you stare at a solution for 10 minutes, then put it away and start typing it into LeetCode, you still probably won’t be able to recall the full solution from memory. You’ll have to use your understanding of the solution to come up with a working submission. As you try to reproduce the solution on day 0, you’ll notice which parts are harder than others. This will start the process of learning the solution, and it can help you find parts of the model solution that need to be updated with a clearer explanation.
1 day
The one-day interval works like this: You practice a solution on day 0, sleep for one night, and try to reproduce the solution the next day without looking at it again. This will expose different facets of the problem that you didn’t see the previous day. Sleeping is good for consolidating memories, but it also starts the process of forgetting. So at this interval, you may find that parts of the problem are difficult to remember. Recalling troublesome parts helps strengthen recall, and as on day 0, it can encourage you to make updates to the model solution description.
2-4 days
For the two-day interval, you practice a problem, skip one day without practicing it, and practice it the next day. For the four-day interval, you skip two days. The 2- and 4-day intervals increase the difficulty of remembering the details of a solution, but they are still short enough that you’ll remember most of the problem, including which algorithm you used and some parts of the code. But you may forget some implementation details if you haven’t practiced similar problems. This is a good time to think about how the algorithm works and how to apply it in more general cases.
8-16 days
At these intervals, you can forget major concepts required to solve the problem. So it’s important to slow down and avoid increasing the interval until you have mastered it at the current length. Since you’ll be practicing other problems in parallel, solutions to multiple problems can get mixed in your mind. You might recall a technique that worked on Problem A and mistakenly using it on Problem B. That provides an opportunity to learn how to map a problem with the solution that works for it, which is an important skill to have when you’re solving unknown problems.
32-64 days
With this amount of time between repetitions, you might completely forget a problem, almost as if you are seeing it for the first time. This shows that you are increasing the repetition interval too quickly. The 32- and 64-day intervals are a good time to make sure you have a solid understanding of every part of the solution, including how to pick the solution approach given the problem description, the high-level plan to implement the solution, any tricky details for particular steps, and finally all the low-level implementation details.
128-256 days
At very long intervals, the only options for solving a problem are 1) Retrieve the solution from your long-term memory, or 2) Figure out the solution from general experience. You won’t be able to rely on short-term memory from recent practice sessions. The goal is to use option 1. The purpose of model problem and solution practice is to learn canonical problems in such a way that you can implement them without thinking too much. For example, you should be able to implement the standard binary search algorithm without thinking about how to find the middle of an array, or considering the pros and cons of lo < hi
vs. lo <= hi
.
The 128- and 256-day intervals are not so much about learning a problem, and more about verifying that it’s really in your long-term memory. After some experience with the spaced repetition process, you should be able to work out every detail of a problem at the shorter intervals, and avoid lengthening the intervals too quickly. Then once you get to the longer intervals, you should always be able to solve the problem. If that works out according to plan, you can now archive the problem to make room for new ones.
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.