Spaced repetition for LeetCode and DSA: a review plan for coding interviews
Published · Updated
Sources checked on by Alexandre Doumergue, founder of Paced.
Why problems fade, and patterns last longer
Two findings from learning research apply directly to interview prep:
- Spread the practice. College students who split ten problems of one kind across two sessions a week apart did much better four weeks later than students who did all ten in one sitting; extra problems in the same sitting did nothing (Rohrer & Taylor, 2006). Grinding twenty sliding-window problems in one weekend is the second group.
- Mix the kinds. When practice problems of different kinds were interleaved, students learned to pick the right method and did better on a later test than students who practised one kind at a time (Taylor & Rohrer, 2010). An interview never tells you which chapter the problem is from.
And the review has to be retrieval: practising recall beat restudying on later tests (Karpicke & Roediger, 2008; Roediger & Karpicke, 2006). Reading your old solution is restudy. What a good recall session looks like is in active recall and spaced repetition.
The unit of review: a pattern, not a problem
If every solved problem becomes something to review, the list grows by several a day and the reviews swamp the new material. Review patterns instead: each one is a topic, and each review is one new problem of that pattern. A working list of 14:
- Arrays and hashing
- Two pointers
- Sliding window
- Stack and monotonic stack
- Binary search (including on the answer)
- Linked lists
- Trees: depth-first and breadth-first
- Heaps and top-k
- Backtracking
- Graphs: BFS and DFS
- Topological sort
- Union-find
- Dynamic programming, one dimension
- Dynamic programming, two dimensions
The order matters less than finishing each pattern's first study properly: the idea, the template, three problems solved with help if needed.
What a review looks like
Paced's Standard pace places the reviews of a pattern at D+1, D+3, D+7, D+15, D+30, D+60 after the first study. For a 2 h first study, the default review lengths are 36 min, 31 min, 26 min, 22 min, 17 min, 12 min. In that time:
- Pick a problem of that pattern you have not solved before (or not in the last month).
- Set a timer. Say or write the approach before coding: which pattern, why, what the invariant is.
- Code it without looking anything up.
- Then check: complexity, edge cases, a reference solution if you got stuck.
- If you could not start, the pattern needs a second first study, not a longer review.
A 10-week plan around a full-time job or classes
14 patterns, two new ones a week for 7 weeks, 2 h per first study, Standard pace, any day of the week a study day. Budget: one hour on five weeknights and three hours on Saturday and Sunday, 11 h a week. Our calculation:
| Week | First studies | Reviews | Total | Fits 11 h? |
|---|---|---|---|---|
| 1 | 4 h | 2 h 14 | 6 h 14 | yes |
| 2 | 4 h | 3 h 06 | 7 h 06 | yes |
| 3 | 4 h | 3 h 50 | 7 h 50 | yes |
| 4 | 4 h | 3 h 50 | 7 h 50 | yes |
| 5 | 4 h | 4 h 24 | 8 h 24 | yes |
| 6 | 4 h | 4 h 24 | 8 h 24 | yes |
| 7 | 4 h | 4 h 24 | 8 h 24 | yes |
| 8 | 0 | 2 h 10 | 2 h 10 | yes |
| 9 | 0 | 1 h 30 | 1 h 30 | yes |
| 10 | 0 | 58 min | 58 min | yes |
What it costs per week
Reviews grow for the first weeks and then hold at about 4 h 24 a week while new patterns keep coming. From week 8 there is nothing new: reviews drop to 2 h 10, then 1 h 30, then 58 min, which leaves the weekends for timed mixed sets and mock interviews.
What happens if you go faster
Three new patterns a week (the same 14 in 5 weeks) on the same budget, our calculation:
| Week | First studies | Total | Fits 11 h? |
|---|---|---|---|
| 1 | 6 h | 8 h 50 | yes |
| 2 | 6 h | 10 h 39 | yes |
| 3 | 6 h | 11 h 45 | no, over by 45 min |
| 4 | 6 h | 11 h 45 | no, over by 45 min |
| 5 | 4 h | 10 h | yes |
| 6 | 0 | 2 h 49 | yes |
| 7 | 0 | 1 h 35 | yes |
| 8 | 0 | 51 min | yes |
The plan breaks in a later week, not the first: from week 3 the reviews of the first patterns arrive on top of the new ones and the week goes over 11 h. If your interview date is close, cut the list rather than the reviews.
Mix the patterns in the last weeks
From week 8, replace pattern-by-pattern reviews with mixed sets: three problems from three different patterns, without the pattern named. That is the interleaving effect in practice, and it is what the interview tests. To lay the weeks out around your own evenings, use the study schedule maker; for one pattern's dates, the spaced repetition calculator.
Using a problem site with this plan
Any problem site or public list works as a source of fresh problems for each pattern: tag the problems by pattern, keep a short log of which ones you have done, and draw the next review's problem from the untouched ones.
LeetCode is a trademark of its owner. Paced is not affiliated with LeetCode.
Paced plans each pattern's first study and reviews inside the evenings and weekends you actually have, moves what you missed, and warns you before a week will not fit. The web plan is free for up to 8 active topics, 7 days ahead, with no card; the iPhone and iPad app needs Plus. Try it without an account.
Questions
Does spaced repetition work for DSA and LeetCode?
Spacing and mixing problem practice both improved later test performance in studies of problem solving (Rohrer & Taylor, 2006; Taylor & Rohrer, 2010). Apply it to patterns, and make every review a fresh problem solved without help.
Should I re-solve the same LeetCode problem?
Not as your main review: you remember the answer, not the method. Re-solve a different problem of the same pattern, and repeat an old problem only after a long gap.
How many problems a day for coding interviews?
Count hours, not problems. In our example, two new patterns a week plus their reviews take 6 h 14 to 8 h 24 a week; three new patterns a week no longer fit 11 h a week from week 3, peaking at 11 h 45 in weeks 3 and 4.
What intervals should I use for coding problems?
Growing gaps work: Paced's Standard pace (D+1, D+3, D+7, D+15, D+30, D+60) for an interview two months away; a tighter one such as Intensive (D+1, D+2, D+4, D+7, D+12…) if it is a few weeks away. The best gap shrinks as the test gets closer (Cepeda et al., 2008).
Can I use flashcards for algorithms?
Cards help for facts such as complexities. Patterns are skills: the review that tests them is writing code for a new problem, which a card cannot hold.
Sources
- Rohrer, D., & Taylor, K. (2006). The effects of overlearning and distributed practise on the retention of mathematics knowledge. Applied Cognitive Psychology, 20(9), 1209–1224. 216 students solving one kind of maths problem: splitting ten problems across two sessions a week apart did nothing at one week but helped a lot at four weeks; extra problems in one sitting (overlearning) did nothing.
- Taylor, K., & Rohrer, D. (2010). The effects of interleaved practice. Applied Cognitive Psychology, 24(6), 837–848. Mixing practice problems of different kinds taught students to pick the right method, and improved a later test.
- Karpicke, J. D., & Roediger, H. L. (2008). The critical importance of retrieval for learning. Science, 319(5865), 966–968. Repeated testing had a large effect on delayed recall; repeated studying after learning had none.
- Cepeda, N. J., Vul, E., Rohrer, D., Wixted, J. T., & Pashler, H. (2008). Spacing effects in learning: A temporal ridgeline of optimal retention. Psychological Science, 19(11), 1095–1102. More than 1,350 learners, review gaps up to 3.5 months, final tests up to a year later.
- Roediger, H. L., & Karpicke, J. D. (2006). Test-enhanced learning: Taking memory tests improves long-term retention. Psychological Science, 17(3), 249–255. On tests two days and one week later, practising recall beat restudying the same text.