Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 6: Model Solutions

By Duncan Smith Feb 15 0

LeetCode 2023

A well-chosen model problem gives you a vehicle for studying a specific concept. When you first select a problem, it’s good practice to see if you can solve it on your own using what you already know about the concept. But a problem is useful for practice even after you have solved it once. A problem that you have already solved is best used along with a model solution.

Selecting a problem you haven’t seen before and solving it for the first time is a good way to simulate what happens in a coding interview. But it’s only one type of practice, and you shouldn’t spend all your time practicing that way. Instead, reserve some of your practice time for problems you have already solved. This is where you need a model solution, which you can think of as the best solution you can create using all the resources available to you.

Once you submit your own solution, compare it with examples like the official LeetCode solution, the solutions posted by others in the LeetCode discussions, and solutions found elsewhere on the Web. This process, known as upsolving in competitive programming circles, is a key part of practicing a problem. Even if the LeetCode online judge accepted your first solution, there are other ideas that you could use to improve your solution, or to make your solution more useful in solving other problems.

The model solution emerges from this research. As you study other solutions, you can rewrite or update your model solution using the best ideas you find. Use your own coding style and make sure you understand each step. Think about whether the solution prioritizes runtime or memory usage, and whether you can write a different version that makes the opposite trade-off. At the end of this process, you’ll have one or two high-quality solutions to your model problem, and a foundation for building solutions to other problems that are based on the same concept.

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