How to Improve Your Coding Skills With Leetcode

Coding skill is critical to a software engineer. Doing leetcode is one of the easiest ways to improve your coding skill. It’s also one of the best ways to prepare for a coding interview.

Over the past few years, I’ve done 1000+ leetcode questions. Now, I can work on most of the medium questions and a lot of the hard questions comfortably. I’d like summarize some of my thoughts about how you can efficiently improve your coding skills with leetcode. I hope they are helpful to you.

Stop Grinding Leetcode Questions

Some people abuse the usage of leetcode by mindlessly grinding a large number of questions in a short time. What they are really doing is just trying to memorize the questions and solutions in the hopes of meeting the same questions in future interviews. While this is possible, it is definitely not the most efficiently way to use leetcode, and the memoization tends to fade away as time goes, so it doesn’t help a lot for the long run.

What Do You Get From Doing Leetcode Questions?

Before we talk about how to do leetcode efficiently, let’s first understand a fundamental question. What do you get from doing leetcode questions?

Leetcode algorithm questions requires us to have two basic coding skills:

  • algorithm design
  • implementation

So when we are working on leetcode questions, what we are really doing is to consolidate our skills to do algorithm design and implementation.

Of the two skills, most people are more comfortable doing implementation than algorithm design. Implementation skill can be easily improved if you practice more. However, algorithm design sometimes seems to be challenging. Sometimes it feels frustrating that you cannot develop ideas when facing a new question even if you have finished hundreds of other questions. Let’s try to understand this problem deeper by “modeling the algorithm design”.

Modeling The Algorithm Design

In order to model the algorithm design process, let’s first build a graph (I’ll call it knowledge base graph later), where each node in the graph can be:

  • a leetcode question (or any other coding question)
  • an existing algorithm (e.g., quick sort, binary search)

If an existing algorithm is a solution to a leetcode question, let’s put an edge in between them. If one question can be converted into another one, let’s also put an edge in between them.

That being said, the process of algorithm design is nothing but searching a connected subgraph from one question node to a set of solution nodes.

If you feel hard to address leetcode questions, that’s because there are just no enough nodes in your knowledge base graph. If certain nodes do not even exist in your knowledge base graph, it is simply impossible to connect certain question to solution nodes. That’s why you can’t figure out a solution for a question no matter how hard you think.

So how do you improve your algorithm design skill, the answer is easy, just complete your knowledge base graph. The more you have in your knowledge base graph, the easier it will be for you to tackle the leetcode questions.

On the other hand, there are definitely efficient ways to search connected subgraph from a question node to solution nodes. I’ll talk about that in future posts.

How To Do Leetcode Efficiently?

When you are doing leetcode questions, please keep in mind that you’d like to:

  • improve our algorithm design skill (i.e., enriching our knowledge base graph)
  • improve our implementation skill

Since these are two separate skills, try to separate the process as well, i.e., you want to think of a clear and working algorithm first, and then work on its implementation.

If you think you can’t figure out an algorithm, that’s totally fine. Look for an answer online. Of course, you do not want to stop there. You want to come back and check which part of your knowledge base graph is missing, and fill it up.

If you are doing leetcode this way for a while, it’ll help you build up your knowledge base graph, and when your knowledge base graph is rich enough, tackling leetcode questions will not be a lot easier for you.