Red-Green-Code

Deliberate practice techniques for software developers

  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter

LeetCode Tip 10: Planning a Spaced Repetition Schedule

By Duncan Smith Mar 15 0

LeetCode 2023

For most programmers, solving coding interview problems is not a natural way of coding. It takes time and practice to get good at them. Using spaced repetition techniques makes this practice time more effective.

The canonical example of spaced repetition is using flashcards to learn language vocabulary. Anki is a popular software application that implements spaced repetition by presenting each flashcard at the optimal time. In vocabulary study, each card is fairly short, just a single word and definition. But there are many cards to learn, since learners need to know thousands of words to become fluent in a language.

For coding interview problems, the quantities and material to learn are quite different. The well-known Blind 75 list, as its name implies, has only 75 model LeetCode problems. Even the largest list on NeetCode has only 327 problems. Each of these problems might require 25-50 lines of code to solve. That’s small by real-world programming standards, but there’s a lot of detail packed into those lines.

Algorithm implementation is a different kind of knowledge than vocabulary definitions. You wouldn’t want to memorize how to implement binary search the way you learn what a word means. Given these differences, you might wonder how applicable spaced repetition is to LeetCode problems. Maybe it’s better to solve a problem once, write a detailed model solution to make sure you understand all the details, and then move on to a new problem.

The problem with this approach is that if you only solve a problem once, you’ll never practice recalling the details of the solution from memory, which means you probably won’t remember how to solve it. Although they represent different types of learning, a complex activity like implementing an algorithm and a simpler activity like defining a vocabulary word both use the brain’s long-term memory functions. Rather than having to re-discover the principles of binary search when you need that algorithm, you can instead remember your model solution. That frees up more of your 30-minute interview to adjust your implementation to the specific problem you need it for.

To make this more concrete: If you want to remember how to implement binary search in a year, it’s not enough to practice once today and again after a year. Instead, start out with small intervals and increase them with each repetition. The basic interval is one full day (since sleep is important for consolidating learning). So when you’re learning a new model solution, start by practicing it every day for a few days. Once that becomes easy, a rule of thumb is to double the time interval after each successful practice session: Two days, four days, eight days, and so on. Adjust the interval times based on how hard a repetition is. If you’re using an eight-day interval and the problem seems very easy, try skipping 16 days and go directly to 32. If it’s too hard, stay at the same interval or cut it in half. Once you get to 256 days, you have probably learned the problem for the purpose of interviewing. You can either remove it from your model problem list to make room for another problem, or just practice it once a year to make sure you still know it.

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.

Categories: LeetCode

Prev
Next

Stay in the Know

I'm trying out the latest learning techniques on software development concepts, and writing about what works best. Sound interesting? Subscribe to my free newsletter to keep up to date. Learn More
Unsubscribing is easy, and I'll keep your email address private.

Getting Started

Are you new here? Check out my review posts for a tour of the archives:

  • 2022 in Review: Content Bots
  • 2021 in Review: Thoughts on Solving Programming Puzzles
  • Lessons from the 2020 LeetCode Monthly Challenges
  • 2019 in Review
  • Competitive Programming Frequently Asked Questions: 2018 In Review
  • What I Learned Working On Time Tortoise in 2017
  • 2016 in Review
  • 2015 in Review
  • 2015 Summer Review

Archives

Recent Posts

  • LeetCode Tip 11: How To Use Spaced Repetition (Part 1) March 22, 2023
  • LeetCode Tip 10: Planning a Spaced Repetition Schedule March 15, 2023
  • Book Review – Algorithmic Thinking: A Problem-Based Introduction, Second Edition March 9, 2023
  • LeetCode Tip 9: Spaced Repetition March 8, 2023
  • LeetCode Tip 8: Anatomy of a Model Solution March 1, 2023
  • LeetCode Tip 7: How to Write a Model Solution February 22, 2023
  • LeetCode Tip 6: Model Solutions February 15, 2023
  • LeetCode Tip 5: Choosing a Model Problem February 8, 2023
  • LeetCode Tip 4: Model Problems February 1, 2023
  • LeetCode Tip 3: A Goal for LeetCode Practice January 25, 2023
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2023 Duncan Smith