Red-Green-Code

Deliberate practice techniques for software developers

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

LeetCode Tip 27: Make Your Model Solutions More Memorable

By Duncan Smith Jul 12 0

LeetCode 2023

A model solution is a place to record everything you think is important about a problem and its solution. If you can learn and remember your model solution, you’ll be able to reproduce the solution to the model problem, and you’ll have a head start on solving similar problems.

When you write your own model solutions rather than relying on pre-written solutions, you can customize them so they make sense to you, which means they’ll be easier for you to remember. Just writing and explaining a solution helps you remember it. But if you find that you can only solve a problem after short intervals and not after longer intervals, that’s a sign that your solution isn’t memorable enough. It’s not enough just to write a good editorial that clearly explains every step of the solution. You also have to write it in a way that helps you recall the key parts of the solution when you need them. Here are some ways to accomplish that.

  • Explain the solution in multiple ways: You can explain a solution using code, pseudocode, code comments, narrative text, static diagrams, animated diagrams, and other creative methods. Each of these gives you a different way to remember the solution. For example, if you’re trying to reproduce a solution and you’re having trouble with the code, remembering the pseudocode may give you what you need.

  • Use diagrams: To get a solution accepted on LeetCode, the only thing you have to submit is code. If your code is accepted, you know that your solution is correct and meets the minimum performance requirements. Once you have the code, it’s easy enough to write a few sentences in your model solution explaining how it works. Drawing a diagram requires a different way of thinking, so a visual representation of the solution, along with narrative text, will help you understand and remember the solution better.

  • Pick good identifier names: Competitive programming has a reputation for encouraging short variable names, which contestants use to write their solutions as fast as possible. Coding interviews also have a time limit. But for learning and remembering a solution, it’s best to pick meaningful variable names, while balancing the need to write the solution under time pressure. If you’re practicing a problem and you have trouble remembering a section of the solution, renaming a variable or function could help make it more memorable.

  • Write hints: LeetCode supplies official hints for many problems, so people can try solving a problem with a hint rather than by jumping directly to the solution. Hints also simulate the experience of a coding interview, where the interviewer is there to help you along if you get stuck. In your model solution, write a few hints, where each hint supplies more information. You can use these when you’re still learning the solution.

  • Record which parts of a solution you don’t remember: A practice journal can help you discover which parts of your solution need to be more memorable. If you remember some parts of a solution but not others, make a note of that. Then use your notes to improve the solution.

  • Make your solution explain itself: In real-world software, log files can help programmers track down the source of a bug. LeetCode solutions can also include logging (usually print statements). These logs can help clarify the steps that a program uses to solve a problem, and the state (values of variables) at each step. When you find test data that produces good log output, copy it into your model solution.

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