In the model problem approach to LeetCode practice, the goal is to focus on specific problems rather than abstract concepts. For example, instead of focusing on the general properties of hash tables, or even hash table syntax in a particular language, find a problem that uses hash tables and study that problem. You’ll still learn the concepts, but you’ll have an implementation to associate them with. Then when you need hash tables to solve a new problem, you can retrieve your model problem implementation (either from memory or from your source code repository) and map it to the new problem.
To use the model problem approach, we need to choose model problems. Some problems make better model problems than others. Here are some principles to consider as you make your choice:
Pick the right problem for your level: To improve at a skill, it’s best to practice problems that are slightly above your comfort level. For a model problem, the requirements are a bit different. Your aim in solving a model problem is to create an implementation that you can use in the future. Much of the skill improvement comes later, when you use your model problem to understand harder problems. For that reason, it’s fine if the model problem is easier than problems you would normally select for practice.
Switch model problems over time: It’s hard to find a single model problem that covers every detail of a programming concept. So once you’re familiar enough with a model problem that you can confidently implement it, find another one that approaches the concept from a different angle. After you do this a few times, you’ll have a set of model problems that provide broad coverage of the concept.
Choose a problem that focuses on the concept: If a problem uses a hash table as its primary data structure, but the hard part of the problem is in some other area, it’s not the best choice for a hash table model problem. One rule of thumb: The easier a problem is (in LeetCode’s Easy – Medium – Hard difficulty system) the more it’s likely to focus on fundamental concepts, and the less creative thinking is required. It’s good to practice creative thinking once you’re familiar with a concept, but learn the concept first.
Check the like/dislike ratio: Each LeetCode problem shows how many users have liked or disliked it. This is one way to filter out problems that rely on tedious implementation details rather than fundamental concepts. You may get tedious implementation problems in interviews, so you have to practice them, but they’re not the best choice for model problems.
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