Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 30: The Problem-Solving Hierarchy

By Duncan Smith Aug 2 0

LeetCode 2023

As you get more experienced at LeetCode practice, you can envision a hierarchy of problem-solving skills, where each level helps with a different aspect of problem-solving.

At the base of the hierarchy is the most concrete skill: Learning a model solution and using what you learn to solve the specific problem for which you wrote the solution. Studying a model solution this way is not just memorization, but it is a very direct way to learn a skill. First, you learn the steps to solve Problem A, and then you use those steps to solve Problem A. With enough repetitions, it provides a good foundation for the “Problem A” skill.

One level up in the hierarchy is a slightly more challenging and abstract practice: Solving a problem using the skills you learned from a similar problem. This describes the main problem-solving loop for LeetCode practice. Start learning a topic, solve a practice problem, learn more about the topic, solve more problems, and so on until you get good at solving problems in that topic tag (at least through the Medium difficulty level). A standardized problem-solving process helps get the most out of this practice loop.

Topic-wise practice can get you a long way into LeetCode practice, since LeetCode consists of problems that are grouped into standard topic categories. But for harder problems, it isn’t enough to know how to solve a general problem type. Hard LeetCode problems are hard because they require more than a cookbook approach. They require creativity. But that doesn’t mean there’s no way to get better at solving them. A canonical book on mathematical problem-solving, How to Solve It by George Pólya, provides a set of principles and strategies to try. For example: use symmetry; consider special cases; solve a simpler problem first. This is more general advice than “find the middle of a sorted collection and determine if the target is in the left or right half.” But because it’s more general, it can apply to more complex problems.

Since How to Solve It comes from the tradition of mathematical problem-solving, it’s a good fit for LeetCode problems, which are often described in mathematical terms. But as an ultimate level of the skill hierarchy, we can examine problem-solving in even more general terms applicable to all areas of science and engineering. As an example, Ozan Varol’s book Think Like a Rocket Scientist uses examples from the Mars rover program and other challenging real-world projects. Some of his advice: reason from first principles; conduct thought experiments; learn from your failures.

It may seem like overkill to learn techniques that got robots to Mars and use them to solve toy software problems. But although well-defined LeetCode problems may be easier than messy real-world problems, that doesn’t mean they are easy. And LeetCode problems can work better for practice than problems that aren’t easily repeatable. So don’t worry that the technique you’re using to figure out a LeetCode problem might be too powerful for that purpose. If you test it out on LeetCode, you may find it coming to mind more readily when you need it for a bigger project.

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