Spaced repetition might seem like a memorization process. In its simplest form, you use spaced repetition by simply reading a prompt and responding with the correct answer. In the LeetCode context, the prompt is the LeetCode problem description, and the answer is an accepted solution. If you solve the same model problem multiple times, you get better at solving that problem and similar problems.
But LeetCode problems and solutions are longer and more complex than standard spaced repetition content, so it doesn’t work to approach them the same way. Here are a few things you can try to do as you use the process.
Improve your model solution
The goal when writing a model solution is to explain the best way to solve the problem, using your own experience and what you have learned from other people’s solutions. But no matter how careful you are to include every relevant detail, you will always find out more about the problem as you practice it. Taking a break from a problem to do other things (including solving other problems) gives your subconscious time to work on it. When you come back to it, you’ll notice additional details, and you’ll probably find that some parts are more difficult than you thought they were when you wrote the solution. Use this insight to improve your model solution. If you had trouble with part of the problem during a repetition, update the solution to explain that part more clearly.
Adjust the problem difficulty
Learning through problem-solving is most efficient when you practice problems that are just hard enough. It’s not useful if they’re so easy that you can solve them in your sleep. And if they’re so hard that you can’t make progress on them, you won’t learn anything either. But it’s not always possible to find problems at exactly the right difficulty level, unless you have an instructor to write problems specifically for you. Spaced repetition can help in this situation. A problem that you have studied previously is easier if you try it again soon after you have solved it, and harder if you wait longer. So you can adjust the difficulty of a problem by adjusting the repetition interval. If it’s too easy, wait longer to solve it again. If it’s too hard, reduce the interval or improve the solution to better explain the hard parts.
Narrow down a problem area
As you practice a problem using spaced repetition, you may encounter the following situation: After practicing a problem a few times at increasing intervals, you remember most of the solution but forget part of it. This is fine. It’s the spaced repetition process working, making you aware of a specific part of the problem that you haven’t completely learned. When this happens, you could reduce the practice interval, which is what the spaced repetition process says to do when you have trouble with a repetition. But if you have already practiced the problem several times at longer intervals, reducing the practice interval may not be the best option. Instead, keep the current interval, but write a detailed analysis of the difficult area in your practice notebook. The reason not to go back to a shorter interval is that while that will help you solve the problem successfully, it promotes a memorization approach. Once you reach an interval of a week or two, the goal is to rely on understanding the solution rather than remembering it. If you remember anything, it will be the general solution structure rather than lines of code. Once you get to this level of understanding of a problem, it’s best to keep using it, even if it means you have trouble solving it. If things still aren’t working out after a few tries with the same interval, it’s fine to reduce the duration. But try the other approach first.
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.