Last week: stars. This week: points (aka coins).

**What is the benefit of getting points in LeetCode?** (answer)

*See A Project for 2022 to find out what I’m working on this year.*

Deliberate practice techniques for software developers

Last week: stars. This week: points (aka coins).

**What is the benefit of getting points in LeetCode?** (answer)

*See A Project for 2022 to find out what I’m working on this year.*

Starting out the year with a fun question about LeetCode gamification:

**How do I earn stars in LeetCode?** (answer)

*See A Project for 2022 to find out what I’m working on this year.*

A few months ago, I noticed something about LeetCode’s daily LeetCoding Challenge: The problems were starting to repeat. This had happened in the past, but not as regularly. At this point, I can say that it’s definitely a trend. Almost every daily problem is a repeat of a problem from an earlier month of the Challenge. It’s not that the challenge authors have run out of problems. LeetCode has over 2000 problems in its library, and the daily challenge has been running for less than two years. At one problem per day, that leaves plenty of unused problems. So they’re doing it for some other reason.

Fortunately, problem repeats are not a big deal. The daily challenge is mainly a way to gamify the process of selecting one LeetCode problem per day to solve. But there’s nothing stopping a LeetCoder from picking any problem they want (assuming it’s an unlocked problem, or they have a premium subscription). In fact, problem repeats may actually be a good thing, as I’ll explain in this 2022 project plan.

Like last year’s project, my 2022 project will be based on LeetCode problems and model solutions. Of course I’ll continue participating in the daily problem, because why not. But as I mentioned last week, solving a problem once provides only limited benefits when it comes to learning new techniques and preparing for interviews. Since I don’t have a lot of time every day to spend on LeetCode, a new problem every day may be too much of a good thing. Having repeated problems in the Challenge means I don’t need to spend as much time on the daily problem, which provides more time to revisit problems that I select on my own.

I already have a full-time job, and I don’t have any interviews planned in the near future. If I wanted to properly learn a new problem every day using the process I described last week, there’s no way I could fit the required study time in my schedule. Instead, I’m planning my project around an in-depth study of one problem per week. Each week, I’ll select a problem from the set of problems I have solved previously during the LeetCoding Challenge, and turn the solution into a formal model solution that’s appropriate for learning and studying.

More specifically, I’ll be focusing this year on finding the hard parts of a problem using a spaced repetition process. As I explained last week, I have been observing how which parts of a coding problem I find challenging depends on when I last looked at the problem. For example, if I solved the problem recently, I can generally remember exact lines of code and just reproduce them. If it has been a long time since I solved the problem, I have to try to remember concepts, and come up with the code based on those.

So in addition to tracking quantitative spaced repetition details like my last practice date and how long a problem took to solve, I’ll also note what made the problem difficult to solve during that repetition. It could be something fundamental about the algorithm, something about that specific problem, or just a programming language syntax issue. This should allow me to target learning difficulties at a more granular level, thereby making the spaced repetition process more efficient.

I plan to keep answering questions on Quora this year.

The biggest change on Quora in 2021 was Quora+, the company’s plan to supplement its advertising income with subscription income. I don’t plan to participate in Quora+ either as a publisher or as a consumer. I’m not inclined to do the former because the dollar amounts involved are too miniscule to offset the annoyance factor for readers. And I’m not interested in the latter because Quora’s content quality is too unreliable to be worth a monthly fee. If Quora implemented the changes suggested by Jon Shore, a subscription might be worth it. But those changes are highly unlikely for both technical and business reasons.

So my Quora answers will continue to be free to read in 2022, and I will continue to share free daily content on Coder vs. Coder.

Good luck in 2022!

(Image credit: Marco Verch)

Programming puzzles like those on LeetCode may have clear specifications and short solutions compared to real-world computer programs, but that doesn’t make them easy. Something about the math and algorithms required to solve them makes them challenging for the average programmer (and many above-average programmers!) This year, once again, I allocated some time each day to work on the LeetCode Daily Problem, both to keep my problem-solving muscles in shape and to find effective problem-solving techniques.

As I wrote in last year’s end-of-year review and in my How to LeetCode post in the LeetCode discussions this year, the foundation for learning LeetCode-style problems is spaced repetition. While solving the daily problem and reading the discussions helps expose you to new problems and solutions, it’s far from enough. Solving a problem the first time provides an introduction to that problem and its associated concepts. But you have to solve a problem repeatedly to really understand it.

One benefit of spaced repetition is the *repetition* part. But it’s not just a matter of solving the same problem five times in a row. While that type of repetition might help you remember it the next day, it won’t do much for remembering it a week or a month later. That’s where the *spaced* part comes in. Gradually increasing the time between repetitions helps transfer the solution into long-term memory, where it’s more useful when you need to retrieve it during an interview.

To wrap up this year, I’d like to explore a specific goal of spaced repetition: learning a solution at multiple levels of abstraction.

In my How to LeetCode post, I explained why it’s useful to write a detailed model solution before investing in spaced repetition practice for a problem. I said this was a way to “polish the solution before you learn it.” In the comments, a reader thought this was backwards. His objection: “I would have thought you’d have to learn it first, and then polish it.”

I think both options can be correct. It’s important to create the best solution you can before you start practicing it. If you’re going to invest time in learning a solution, you want it to be as good as you can make it. But it’s also true that practicing a solution can illuminate parts of it that you didn’t notice when you first studied it. So it’s a virtuous cycle: as you practice a solution, you learn more about it, which helps you understand it better, which makes it easier to remember, which makes future practice more effective, which allows you to see new aspects of the problem that you can incorporate into your practice.

A model solution works best when it expresses the solution to a problem at different levels of abstraction, from most general to most specific: Begin with a summary of the problem and the overall solution approach. Then explain the algorithm step by step in natural language, without any code or pseudocode. (Though variable names may be useful at this point to make the explanation clearer). Next, write the algorithm in pseudocode, avoiding any language-specific details. Finally, write a real implementation that compiles, runs, and passes all the test cases.

This multi-layered approach helps you understand the solution better, and therefore remember it better. Each level of abstraction explains the problem from a different point of view. At the top level, learning the problem and solution summary for multiple problems helps you recognize problem types and remember which algorithms or techniques are required to solve them. At the next level is the natural language description, which is the core of the solution. It’s how you’ll describe the solution to an interviewer so they can approve what you’re about to implement. After that, you have the pseudocode solution, which a detailed description of the algorithm itself. Then, since the purpose of a coding interview is to prove that you can actually write code, you have to take the process a step farther and actually implement the pseudocode in a real programming language. (It’s worth noting that at least one well-known algorithm textbook doesn’t bother with this step, and just sticks with pseudocode).

The spaced repetition process can help you discover how well you know a solution, as measured by how much time elapses before you forget it. For example, if you practice a solution one day, and you can still successfully reproduce it the next day, that gives you some information about how well you know it. The next step is to increase the length of time between repetitions. So you might practice it again in 3 days and successfully reproduce it again, but then find that you’re unable to reproduce it 7 days after that. So the appropriate repetition time based on your current level of understanding is greater than 3 days but less than 7 days. According to learning theory, you’ll get the best results by practicing again during that interval.

In addition to narrowing down the appropriate practice interval, spaced repetition can also narrow down what part of the solution needs the most practice. To do this, ask yourself after an unsuccessful solution attempt what part of the solution you forgot. If you tried to solve the problem with the wrong algorithm, then you need to start from the beginning and learn the high-level summary. If you knew the general approach but couldn’t make much progress on the details, you can study the natural language solution. If you have a fairly good understanding of the solution details, but you missed a few steps, studying the pseudocode can help. And if you can write a pseudocode solution but have trouble translating it into a programming language, it might be best to review language syntax and common idioms used in LeetCode-type solutions.

Spaced repetition practice can give you very specific feedback about your model solution. I was recently practicing LeetCode 227: Basic Calculator II, which I wrote about at the beginning of this year. At the time I wrote the article, I had practiced the solution at a few different time intervals, and it seemed fairly clear to me. But coming back to it late in the year, I noticed that I didn’t know exactly how the `prev`

and `result`

variables were related. If I was updating the model solution now, I might explain it like this: We need two variables because the problem defines two priorities for operator precedence: multiplication/division (higher priority) and addition/subtraction (lower priority). Since addition/subtraction is the lowest priority, we can update `result`

immediately after any addition/subtraction operation. To account for the higher priority of multiplication/division, we need a separate variable `prev`

that only gets updated after those operations.

No doubt that explanation can still be improved. But you don’t have to guess about when your solution needs to be updated. By keeping track of which parts of the problem you find difficult during spaced repetition practice, you can improve your model solution and remember it better the next time around. As long as you continue practicing a problem, you can keep polishing the model solution, making gradual adjustments to improve its effectiveness as a study tool. The only time a model solution should stop changing is when you know a solution well enough that you can reproduce it on demand whenever you need to.

Last week’s question was about what do to on LeetCode. This week, it’s *what not to do*:

**What are some mistakes to be avoided when you are preparing for LeetCode?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

The LeetCode meta-question:

**How do I step up LeetCode skills for a coding interview?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

LeetCode doesn’t have a difficulty level called *Very Hard*, but this is still a good question:

**Is it worth spending time solving LeetCode’s very hard problems?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

A good question to think about when working on any kind of technical problem set:

**When practicing on LeetCode, how many minutes should I attempt on each question before I look at the solutions of others?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

Language questions like this one attract some strange answers:

**Is C# good for competitive programing?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

A question about practice techniques:

**Would study methods practiced by performing musicians work for competitive programmers?** (answer)

*I’m writing some answers on Quora this year. For more information, see A Project for 2021.*

- 1
- 2
- 3
- …
- 37
- Next Page »