Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 48: Beyond Model Solutions

By Duncan Smith Dec 6 0

LeetCode 2023

The premise of these tips is that the best way to get better at LeetCode is to systematically learn model solutions to model problems. Just solving more problems (the problem quantity approach) or just solving problems at the right difficulty level (the problem quality approach) is not an efficient way to improve at LeetCode. Instead, you have to work through the LeetCode topics and learn the patterns for each topic. The preceding tips explain how to do that.

But there’s one skill that this process doesn’t directly address: solving problems you haven’t seen before. Given a problem in a topic that you have learned thoroughly by practicing model problems, you need to be able to solve a new problem in that topic. This is, of course, the goal of LeetCode practice. So at some point, as you’re learning a topic, you have to decide that it’s time to go beyond model problems and solutions.

Practice

Although solving model problems certainly involves practice, it’s a different type of practice from solving new problems. Solving model problems involves repeating skills in order to learn them better. To practice solving new problems, you just solve more problems. At this point, the quality plus quantity approach can work. Just solve more problems at the right difficulty level. (Solving a bunch of easy problems after you’re already good at a topic won’t make you any better at it). Quantity works at this point because you are applying skills you’re already good at. As you practice more problems, you reinforce these existing skills. And it works because most new problems will have a detail or two that you haven’t encountered in your study of model problems. As you solve more new problems, you’ll encounter more details that will round out your knowledge of a topic.

Problem-solving skills

If you try to solve a moderately difficult problem in a topic before you have learned that topic, you’re unlikely to be successful. Maybe you’ll manage to invent binary search completely from scratch. But you won’t be able to do that for every topic. So you have to learn the topics before moving on to practice.

Learning a LeetCode topic starts with learning information, like the steps of an algorithm, and learning to apply that information by solving specific problems. But at some point, you’ll have a solid grasp of how the topic works and how you can use it. Then what remains is practicing more general problem-solving skills. And although experts have come up with general principles for solving problems, there are a lot fewer of these principles than there are topic-specific principles. In fact, there’s a good argument that general problem-solving skills are really just the combination of many topic-specific skills. So while you can keep general principles in mind, you should spend most of your time on specifics.

When to start solving unknown problems

Although LeetCode has topic-focused courses that teach the fundamentals of a topic, it’s easy to get into a mode of just solving random problems using the daily challenge and the weekly contest. It requires effort and focus to go topic by topic instead. But learning a topic has diminishing returns. After you learn the basics of a topic, you should occasionally try solving a new Medium-level problem, to test your mastery of that topic. When you finish a new problem, evaluate how the process went. If you remembered all the applicable details of the topic, even if you struggled with other aspects of the problem, you may be ready to stop using model problems and solutions to learn that topic. Similarly, it’s good to spend some time practicing problems without knowing which topics apply. This is the situation you’ll be in when you’re in a coding interview, so it’s important to evaluate your performance in those circumstances.

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:

  • 2023 in Review: 50 LeetCode Tips
  • 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

  • Do Coding Bots Mean the End of Coding Interviews? December 31, 2024
  • Another Project for 2024 May 8, 2024
  • Dynamic Programming Wrap-Up May 1, 2024
  • LeetCode 91: Decode Ways April 24, 2024
  • LeetCode 70: Climbing Stairs April 17, 2024
  • LeetCode 221: Maximal Square April 10, 2024
  • Using Dynamic Programming for Maximum Product Subarray April 3, 2024
  • LeetCode 62: Unique Paths March 27, 2024
  • LeetCode 416: Partition Equal Subset Sum March 20, 2024
  • LeetCode 1143: Longest Common Subsequence March 13, 2024
Red-Green-Code
  • Home
  • About
  • Contact
  • Project 462
  • CP FAQ
  • Newsletter
Copyright © 2025 Duncan Smith