Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 4: Model Problems

By Duncan Smith Feb 1 0

LeetCode 2023

The first goal of LeetCode practice is to learn how to solve problems associated with one concept. A LeetCode tag identifies each concept, and each problem has one or more tags. In the beginning, you don’t have to worry about learning concepts more granular than a tag, determining what concept an unknown problem is looking for, or solving a problem within a time limit. Those are all worthwhile skills to learn, but they are better left for later.

Although focusing on one tag is a narrow goal, let’s narrow it down a bit more. The hash table tag currently has 449 problems. To get started, we could solve the first easy problem, read a textbook chapter about hash tables, or check if one of LeetCode’s Explore cards covers hash tables. Instead, I suggest approaching the goal by starting with a model problem.

Serious study of algorithms and data structures often begins when you take a course, and such courses rely on practice problems. (Programming is a skill that you can’t learn just by reading about it). The model problem approach combines problem-based learning with the strengths of the LeetCode platform. The idea is to pick a concept, then find one or more problems that apply that concept in a way that you find understandable. When you need to apply the concept to a new problem, you can then draw on your experience with the model problems.

For example, let’s say you’re starting one of the 449 hash table problems. One approach would be to think about what you know about hash tables — you can insert and retrieve data in (average) constant time, you can store key/value pairs, each key must be unique — and map them to aspects of the problem. With the model problem approach, you instead think about a specific hash table problem that you have learned well, and you map parts of that problem to the new problem. Rather than concepts or pseudocode, you can map blocks of actual code. When you learned the model problem, you practiced correct syntax and typical usage patterns, so you have examples in your head of how hash tables help solve a specific problem. You can apply this practical knowledge to the new problem, rather than having to first translate hash table theory into practice.

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