How to Remember LeetCode Solutions: The DSA Retention System That Actually Works

May 25, 202611 min read
interview-prepdsaleetcodecareer
How to Remember LeetCode Solutions: The DSA Retention System That Actually Works
TL;DR
  • Re-derive, don't re-read: closing your notes and writing solutions from scratch builds recall; re-reading only builds recognition
  • Generation effect (Slamecka & Graf 1978): actively producing information burns it into memory far better than passive reading, even when reading feels like understanding
  • Pattern log over problem list: one entry per pattern with a signal detector, core invariant, skeleton, and mistake log
  • SM-2 spaced repetition cadence: review at 1d → 6d → 15d → 35d → 80d, scaling the interval by how cleanly you recalled
  • Interleaved beats blocked practice: mixing pattern families each session trains identification, not just execution — 63% vs 20% retention on delayed tests
  • Mistake log: the highest-signal pre-interview document you own; read it the morning of your interview, not the solutions

You solved the problem. Understood the solution. Felt genuinely good about it. Two weeks later, the interviewer reads you something that looks almost identical, and your brain produces nothing. Not even the vague outline of an approach. Just silence and a slowly rising heart rate.

This is not a memory problem. It's a study method problem. How to remember LeetCode solutions long enough for them to matter under pressure comes down to four changes in how you practice, and none of them are particularly mysterious.

Most engineers "review" a problem by reopening their old solution, skimming it, thinking "right, that's how it works," and closing the tab. That's not review. That's reassurance. Your brain sees familiar code, fires a quick recognition signal, and calls it a day. The knowledge feels solid. In an interview room, with no code to look at, it isn't there.

The fix has four parts: re-derive instead of re-read, organize by pattern not by problem, space your reviews at intervals that match how forgetting actually works, and interleave different pattern families in every session. None of these are new ideas. The difference is putting all four together and actually doing them.

Why Your Brain Lies to You: Recognition vs Recall

Recognition is cheap. When you read code you've seen before, your brain does something like visual pattern matching. The shapes look right. The logic flows. You feel understanding. But what you're actually feeling is familiarity.

Recall is expensive. It requires reconstructing the solution from semantic memory with no prompts. That's exactly what happens in an interview. The problem statement gives you nothing except the problem.

Reading a solution until it "makes sense" trains recognition. Interviews test recall. These are not the same cognitive skill. You can build one for months without touching the other.

The Ebbinghaus forgetting curve makes this worse. Without active reinforcement, roughly 50% of new information is gone within an hour and 70% within 24 hours. But the forgotten 70% doesn't feel gone when you're re-reading it. It feels present because recognition kicks in. You only discover the deficit when the prompts are removed, which is precisely when it's too late to do anything about it.

A pirate confidently declaring "THAT'S IT? THAT'S INVERTING A BINARY TREE? THAT'S JUST SWAPPING FIELDS WITH RECURSION"

Recognition in action: you read the solution, it clicks, you feel great. The interview has other plans.

Re-Derive. Don't Re-Read.

In 1978, Slamecka and Graf ran a set of experiments that defined what's now called the generation effect. The finding: people retain information significantly better when they actively generate it themselves compared to reading it. Not a little better. Consistently better across cued recall, free recall, and recognition tasks.

This is why re-deriving a solution from scratch beats re-reading it every time. When you close your notes and write the solution yourself, you're forcing semantic encoding. You have to reconstruct the invariant, the edge cases, the order of operations. When you re-read, you're doing surface-level processing. The two are not equivalent, even if they feel like they take the same amount of time and accomplish the same thing.

The struggle when you blank is not wasted time. That's the moment where the memory consolidates. The difficulty is the mechanism. Bjork calls this "desirable difficulty": study conditions that slow down immediate performance but dramatically improve long-term retention. Your brain is not being slow. It's doing the work.

In practice: on review day, open a blank editor. No notes, no previous solution. Write the solution from scratch. If you blank after five minutes, glance at the pattern name only, then try again. Compare to your reference only after you've written something.

If you finish in three minutes and feel completely comfortable, either you genuinely own the pattern or you're relying on residual familiarity. Test it by changing one constraint. "What if the array isn't sorted?" "What if k can be zero?" A real solution survives the variation. A memorized surface-level scan doesn't.

Build a Pattern Log, Not a Problem List

Most people's revision notes look like this: a spreadsheet of 200 problems with columns for "solved," "difficulty," "date." This is the wrong unit. You don't want to know which problems you've solved. You want to know which patterns you own.

A pattern log has one entry per pattern, not one entry per problem. Each entry has four fields:

Signal: What in the problem statement tells you this is the right pattern? Not the pattern name. The actual phrasing. "Longest subarray with at most k distinct characters" maps to sliding window. "Lowest common ancestor" maps to DFS with backtracking or binary lifting. If you can't write a two-sentence signal detector for a pattern, you don't know when to use it.

Core invariant: The one insight that makes the pattern work. For sliding window: "expand right to include, shrink left to restore validity." For two pointers on sorted arrays: "one pointer eliminates candidates from above, one from below." One sentence. If you need more, split it into two patterns.

Skeleton: 15-20 lines of pseudocode. Not a full working solution. Enough to prime the derivation. This is what you look at if you blank completely during re-derivation.

Mistake log: One line per mistake you've made while practicing this pattern. "Forgot to handle empty input." "Initialized window size incorrectly." "Used index instead of value in the heap comparison."

Your mistake log is a map of exactly where your knowledge leaks. The day before a real interview, you don't need to re-read solutions. You need to spend 20 minutes reading your mistake logs. That's where the remaining gaps live.

The goal of organizing by pattern is to build the discrimination skill: being able to look at an unseen problem and quickly narrow down which pattern family applies. LeetCode problem numbers don't help you build that. A problem spreadsheet doesn't either. Pattern-centric organization does.

Schedule Reviews Around Forgetting, Not Comfort

Forgetting follows a curve. Steep early, flatter later. If you review at the right intervals, each review resets the curve at a higher baseline. Too early and you're wasting a session on something you already know. Too late and you've forgotten enough that the review costs more effort than it should.

The SM-2 algorithm, the formula behind Anki, encodes this in simple math. First review: 1 day after solving. Second review: 6 days later. After that: previous interval multiplied by an ease factor that starts at 2.5 and adjusts based on how well you recalled it. The sequence looks roughly like: 1d, 6d, 15d, 35d, 80d, then you probably own it well enough to skip months.

You don't need Anki to use this. A spreadsheet with three columns works: problem name, last reviewed, next review date. After each review session:

  • Solved cleanly: multiply current interval by 2.5, round up, that's your next date
  • Solved with struggle: multiply by 1.3
  • Blanked: reset to tomorrow

A problem you revisited three times at the right intervals will outlast twenty re-reads. The math isn't magic. It's just scheduling practice to coincide with the moment just before forgetting, which is when reinforcement is most effective.

One practical note: if you miss a week of reviews and the queue builds up, don't try to catch up chronologically. Reset all overdue reviews to today's date and work through them. Trying to backfill creates pressure that makes you rush, and rushed active recall doesn't stick.

Blocked Practice Fails When Nothing Is Labeled

Most spaced repetition systems have a blind spot here. You add all your sliding window problems to the review queue, they come due, and you review them together. Then all your DP problems. Then all your graph problems. This is blocked practice, and it creates a specific failure mode.

When you review five sliding window problems in a row, you're not practicing the skill of recognizing that sliding window applies. You're practicing the skill of implementing sliding window once you already know that's what you need. The pattern is pre-labeled by your own queue. In real interviews, nothing is labeled. The problem just exists. You have to figure out what it is.

Robert Bjork's research on this is stark. In one study, participants learning volume formulas for geometric shapes scored 63% on a delayed test when trained with interleaved practice, versus 20% for those trained with blocked practice. Not better. Three times better. The same material, wildly different outcomes, based only on the order of review.

Blocked review builds execution skill. Interleaved review builds identification skill. Interviews test identification first. You have to select the pattern before you can apply it. Blocked practice never trains the selection step.

In practice: each review session should contain problems from at least three different pattern families. A two-pointer problem, then a tree DFS problem, then a DP problem. Force yourself to switch modes. The moment of switching is where discrimination learning happens.

A shooting star with caption: "I wish I could ace the interview without grinding LeetCode"

Everyone has this wish. The retention system is the difference between grinding 300 problems and grinding 80 the right way.

What a Real Review Session Looks Like

Twenty-five minutes. Three problems.

For each problem: look at the pattern name in your log for thirty seconds. Read the signal detector you wrote. Close everything. Open a blank editor and write the solution. You have eight minutes.

After eight minutes: compare against your reference. Note what you missed. One line in your mistake log.

That's it. Three problems, 25 minutes, one mistake-log update per problem. Draw from different pattern families in each session. Set a timer. The time pressure forces full commitment; without it, you'll drift between half-trying and half-checking.

The compounding effect is real. After six weeks of this cadence, your mistake logs get shorter. The patterns you were blanking on start coming back faster. The signal detectors you wrote become the actual mental model you use in interviews, not just notes you wrote once and never revisited.

Retrieval practice research published in Educational Psychology Review found that students using distributed retrieval practices maintained scores after 30 days while blocked-practice groups experienced up to 60% knowledge loss. The mechanism is the same: recall at the right spacing, not review at comfortable familiarity.

If you want to add one more layer, SpaceComplexity runs voice-based mock interviews where you have to talk through your approach and handle follow-up questions in real time. Deriving a solution silently is one skill. Narrating while you derive it, under a time limit, with someone waiting for you to finish, is a different one. The retention system gets you to recall. Practice under conditions builds the performance.

What to Keep

  • Re-read vs. re-derive: Re-reading builds recognition. Solving from scratch builds recall. Interviews test recall. You've been optimizing the wrong thing.
  • Generation effect: Struggling to produce information yourself burns it in more effectively than reading it, even when reading feels like understanding.
  • Pattern log: One entry per pattern, not per problem. Signal detector, core invariant, skeleton, mistake log. Four fields.
  • Review cadence: 1d, 6d, 15d, 35d, 80d. Adjust by how well you recalled. A spreadsheet is enough.
  • Interleave: Mix pattern families in every session. Blocked practice creates a false sense of mastery and collapses the moment patterns aren't pre-labeled.
  • Mistake log: The most valuable document in your prep. Read it the morning of your interview, not the solutions.

The people who build real retention are not practicing harder. They're practicing in a way that matches how memory actually works.


If the system in this post looks familiar, you might also want why practicing LeetCode wrong is costing you, how active recall differs from recognition in DSA practice, and a deeper look at spaced repetition applied to algorithm problems.

Further Reading