What if you carefully implement Tips 1 through 49, and they just aren’t working? You study your model problems, but when you repeat them after a week or two, you can’t remember the relevant details. You learn a LeetCode topic in depth, but when you try to solve a new Medium problem in that topic, it seems to require different skills from the ones you learned when you were practicing relevant model problems.
In other words, LeetCode can be hard, even when you’re working on a problem labeled Medium.
Next week, I’ll review all the tips from this year. But in this last tip, let’s focus on the core of the model problem and solution system, in case you are finding that it isn’t performing as advertised.
First, it’s good to notice that something isn’t working. Although practice is the only way to improve, it doesn’t guarantee improvement. Consistent, focused practice can fail to produce results. Observing that results aren’t happening is the first step to adjusting your practice to make it work better. Tips 1-49 provide a lot of ideas about what kind of practice works best in general, but it’s up to each person to adjust their practice until it works for them.
And eventually it will work. LeetCode topics are designed to be learned. They are based on the curriculum that computer science students study before they get to the hard problems of research or industry. It’s true that most students don’t learn them to the level required to excel in a coding interview. And it may take much longer than you want to get to that point. But learning them is a step-by-step process with no magic or luck required. (Getting a job at any particular company does require some luck, but that’s the nature of coding interviews).
Let’s distill the model problem and solution process down to two elements.
Element 1: Learn a smaller concept
At its core, the system described in Tips 1-49 is based on model problems and model solutions. But a problem may be too big to learn all at once, even after you have practiced it several times. Fortunately, every problem is made up of smaller parts. To practice effectively, figure out which of those parts is giving you trouble. Suppose you’re learning binary search and it isn’t clicking when you try to use it for Medium problems. Maybe you don’t completely understand the loop condition: given how the loop is set up, why does the function always terminate, and when should you use lo <= hi
vs. lo < hi
. Rather than trying to understand these elements using the full binary search problem, write a smaller program that focuses only on the loop condition. Or use math and diagrams to analyze it, if that’s what makes more sense to you.
By carving up a LeetCode problem into smaller and smaller pieces, you can always reach the point where the concept you’re learning is small enough that you can completely understand it, internalize it, and remember it indefinitely. It does take time to deconstruct and learn problems this way, and it takes a different amount of time for each person depending on their innate ability and their background. But it eventually works.
Element 2: Spaced repetition
Once you find a section of a problem that’s small enough to learn, learning it comes down to spaced repetition. No matter how well you study and understand a concept, or how small that concept is, you won’t completely know it until you can reproduce it over days, weeks, and months. The spaced repetition process helps you learn things and also shows that you know them. It is compatible with the strengths and weaknesses of our brain.
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.