As you use a spaced repetition process for LeetCode practice, there are more things to keep in mind than just reproducing the solution correctly. Here are more tips to get the most out of the process.
Make sure you’re practicing the right problem
Before you start spaced repetition practice, you need to choose a model problem and write a model solution. But it may take several repetitions to figure out whether the problem you selected is the best problem for your current level of mastery of a topic. If you write a detailed solution for a problem and refine it over several repetitions, but you still have trouble reproducing the solution, it may be best to leave that problem for later. Maybe the problem combines multiple techniques in a tricky way, or builds on fundamentals that you haven’t yet mastered. It’s fine to switch to another problem in the same area, and come back to the original problem later. Spaced repetition works well to strengthen your understanding of a topic, but it’s not designed for learning a topic from scratch.
Understand the solution rather than memorizing it
Another advantage of spaced repetition is that it tells you when you’re trying to memorize a solution rather than learning it. For short practice intervals (up to a few days), you won’t know for sure whether you really know a solution. Although you may succeed in reproducing it, this could be because you remember it from the previous interval. But as you increase the interval length, it becomes increasingly difficult to remember a solution unless you understand it (unless you’re using sophisticated memorization techniques, which are better for card tricks than programming). So once you get to a 15- or 30-day interval, you can be confident that you know how the solution works, not just how to reproduce the code.
Develop building blocks to use for other problems
Repeating a problem that you have already solved uses skills that differ from the ones required to solve an unknown problem. But the first type of practice can help with the second. For example, if you encounter an unknown problem that seems like it may need a binary search solution, that knowledge won’t help unless you can implement binary search. So as you write your model solutions, remember that you’ll need to use these solutions for other problems in the future. When possible, write them in a way that isn’t too specific to the problem at hand. Some competitive programmers use this approach by assembling a code notebook to use as a guide for implementing tricky algorithms. But interviewers generally don’t allow this type of notebook, since they want to see you write code yourself. So for interviews, it’s best to keep the notebook in your head.
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.