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