Unlike a real-world software project, LeetCode is set up for effective practice. But what is effective in general may not be effective for you specifically. So it’s worth thinking about the best way to practice. The framework I use is explained in Deliberate Practice for Software Developers. Let’s see how the five elements of deliberate practice apply to LeetCode.
Deliberate Practice Element #1: “It’s designed specifically to improve performance”
The LeetCode website is designed to help programmers prepare for coding interviews. So we could delegate responsibility for Element #1 to the LeetCode product managers and call it good. But that would ignore many improvements that you can make to optimize your own practice process through experimentation. By considering your goals, choosing problems carefully, writing detailed model solutions, using spaced repetition with carefully chosen interval lengths, writing a daily practice journal, and considering the other advice in these LeetCode tips, you can make your practice more effective than just opening the LeetCode website and going for it.
Deliberate Practice Element #2: “It can be repeated a lot”
This element doesn’t only mean repeatedly solving LeetCode problems. The skill that you need to repeat is more granular than one problem. Although you need to be able to solve a problem from beginning to end, and it’s essential to practice full problems, it’s also important to focus on smaller skills. As you practice problems, look for areas of weakness in skills like reading problem statements, translating a solution into pseudocode, fluently using the features of a programming language’s syntax and libraries, and selecting and implementing algorithms and data structures. When you run into trouble in one of these areas, find a way to practice it in isolation. The LeetCode website focuses on problem-level practice, so you may need to look elsewhere for some of these. CodingBat is a website that offers practice problems for more granular skills, though its features are rudimentary compared to LeetCode.
Deliberate Practice Element #3: “Feedback on results is continuously available”
The LeetCode UI is all about feedback. You get feedback through compiler errors, test failures, test data for failed tests, and the CPU and memory usage graph. But as with Element #2, you shouldn’t stop with the most obvious sources of feedback. You can generate useful information by tracking how much time you spend on each problem, writing notes in your practice journal, and comparing other implementations to your own. The goal is to determine exactly where your weaknesses are so you can focus your practice on them. This will accelerate your rate of improvement beyond what you would get just by practicing problems.
Deliberate Practice Element #4: “It’s highly demanding mentally”
LeetCode features can lead you astray when it comes to Element #4. Features like the daily challenge problem, the submissions graph, badges, and the solved problems counter. These are gamification features that are useful for building a regular LeetCode habit. But they aren’t always the best choice for deliberate practice. The daily problem might be too easy, might focus on a concept other than the one you’re currently studying, or it might be too easy or too hard. The submissions graph and problem counter might encourage you to submit a problem every day without thinking enough about what you’re getting out of that problem. So use these features to maintain your practice habit, but also set aside time to intensively practice the areas that you need to get better at.
Deliberate Practice Element #5: “It isn’t much fun”
Here’s a question from Reddit: Is competitive programming really worth it?
The top-voted answer:
It’s a hobby like any other. It’s like asking if making model trains is ‘worth it’.
Competitive programming and coding interview preparation aren’t the same thing, and people might be less likely to label LeetCode “a hobby like any other.” Nevertheless, preparing for programming competitions can be serious business, and is often used to get better at coding interviews. So it’s not all fun and games.
The message of Element #5 is that getting better at a skill requires hard work. So don’t be afraid to enjoy it, but if your goal is self-improvement, make sure that’s what you’re focusing on.
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.