Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 29: Use a Problem-Solving Process

By Duncan Smith Jul 26 0

LeetCode 2023

Learning a model solution is worthwhile because it gives you a process for solving similar problems. If you know how to analyze and solve one binary search problem, you can apply it to similar situations where you have sorted data and need to search for a target value. The more model solutions you know, the more likely you are to have a ready solution for any given LeetCode problem.

But while model solutions give you a detailed guide for solving similar problems, you won’t always get a problem that you can directly apply them to. So it’s best to see model solutions as an important component of a complete problem-solving process. Here’s an example of such a process for solving any LeetCode problem, even if it’s different from any problem you have learned previously.

Select a problem and open it.

This could be the daily challenge problem, a contest problem, or a model problem that you’re learning.

Start a timer

How long you take to solve a problem can tell you a lot about your progress, especially once you have some historical data about the time these problems typically take. A LeetCode contest or a coding interview has a built-in time limit. But even when you’re practicing on your own, you can compare your performance to previous attempts for the same problem, or to similar problems. The LeetCode problem page even has an integrated timer.

Analyze the problem statement

LeetCode problems are written in an academic style that many people find unintuitive. And sometimes they are just written poorly. The purpose of the analysis step is to convert the original problem into a format that makes more sense to you. Then you don’t have to keep going back to the original statement while you’re solving the problem. At a minimum, make notes about the input format, output format, and what your solution is expected to return.

Solve the problem on paper

Now that you understand what the problem is asking for, or you have some reasonable guesses, sketch an idea for solving the problem. This is the step where you might bring in a model solution that you have previously studied.

Write a pseudocode version of your solution

Pseudocode is a useful way to clarify an algorithm without getting bogged down in syntax or other implementation details. Convert your solution idea from the previous step into pseudocode. As you do this, you may find that you don’t understand certain parts of the solution well enough to write them as an algorithm. In that case, it’s good to work these out before you get to the coding step.

Translate your pseudocode into actual code

Now you have to work out any details that you skipped during the pseudocode step, including syntax and library details. Writing actual code is part of most coding interviews, so make a note of any areas where you find it difficult to translate an abstract algorithm into code. You can focus on these later during your study process.

Test and debug

LeetCode gives you a few test cases and lets you add your own. Unlike some platforms, the LeetCode judge even tells you what the correct answer is for any test case, which makes debugging easier.

Submit (and maybe debug some more)

LeetCode’s hidden test cases are trickier than the practice cases, so you may have more debugging to do in this step.

Stop the timer and record your elapsed time

Once you get an accepted solution, record how long it took you.

Read other solutions

Even if your solution was accepted, it’s probably not the best solution that anyone has ever submitted for this problem. Part of the learning process is seeing what other people have come up with. When you find good ideas, you can incorporate them into your model solutions.

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