There seem to be many misunderstandings about Leetcode (or algorithm problems), such as the need to memorize all Leetcode problems before going for an interview, or that algorithm problems are intelligence tests (so problem-solving ability cannot be improved through practice). Many people criticize algorithm interviews as being disconnected from work, but we have no control over how each company interviews candidates, and discussing this has no help in passing the interview. Here I want to share how I use deliberate practice to practice algorithm problems.

## Leetcode

Leetcode is an online problem-solving website that collects many algorithm problems that software companies ask during interviews. Currently, there are more than two thousand algorithm problems. Basically, if you are not looking for a job full-time, it is impossible to solve all the problems or even memorize them, and there is no need to solve all the problems. There is a weekly contest held once a week and a biweekly contest held once every two weeks. After the contest, the problems will be put into the problem bank, so the number of future problems will only increase, and the time it takes to complete all the problems will only increase. However, there is no need to complete all the problems.

## Weekly Contest

Leetcode has two regular contests, one on Saturday 14:30 (GMT+0), once every two weeks, and the other on Sunday 2:30 (GMT+0), once a week. Everyone starts with a rating of 1500 points. If your ranking in the contest results is better than your expected ranking based on this score, you will gain points. The more you exceed your expected ranking, the more points you will gain. Conversely, you will lose points. If you have participated in enough contests and your problem-solving ability has not changed, this score will converge and no longer change.

It is strongly recommended to participate in weekly contests to understand your true problem-solving ability and become familiar with solving problems under time pressure. The weekly contest rating is also a way to observe your own progress. If your rating does not improve or even decreases after several consecutive contests, you need to review whether there is any problem with your practice method. The weekly contest rating can roughly reflect a person’s problem-solving ability, while the number of solved problems almost cannot. Stop looking at the number of solved problems! Each contest will have four questions: one easy question, one slightly simple medium question, one slightly difficult medium question, and one hard question. Participating in contests can also earn Leetcode points which can be used to exchange for free premium membership.

## Deliberate Practice

Deliberate practice has only one key point: The fastest way to improve is to practice in a place that is slightly more difficult than your comfort zone. Therefore, the steps are as follows:

- Find out where your level is.
- Find problems that are slightly higher than your level.
- Repeat practicing the problems found in step 2 until you are familiar with them, indicating that your level has improved and you can find more difficult problems to practice.

Leetcode’s weekly contest can help us find out where our level is. Below we will introduce tools for rating problems to help us find problems that are slightly higher than our level. There is no need to waste time writing problems that you already know how to solve. Writing more will only improve your typing speed and will not help your problem-solving ability at all. Therefore, it is not important how many Leetcode problems you have written; what matters is which difficulty level of problems you can solve independently.

### Leetcode Assessment

Leetcode has an assessment feature under the interview tab. It will randomly select problems to form a problem set and give us some time to answer them. After it ends, it will give a score based on the number of test data answered correctly, the number of uploads and the speed of solving problems. This score is not important; what matters is that it has an insight function that analyzes which topics we perform better or worse based on our answers. The best performance is `Looking good`

, followed by `Getting there`

. This feature is great because when we solve a problem we don’t know which topic it belongs to; it’s just like when we’re interviewing or competing; and it tells us how well we’re doing in each topic so we can decide on the amount of practice and difficulty of the problem based on that information. Generally speaking, for me `Looking good`

topics can directly practice hard problems while `Getting there`

can start with medium problems. However sometimes Leetcode’s problem difficulty classification is not very accurate so it’s still necessary to practice problems that are slightly beyond our level to really practice.

### Leetcode Problem Rating

On Github, a user named `zerotrac`

calculated the rating of each problem after the 63rd weekly contest based on the number of people who solved the problem in each weekly contest. The basic concept used is the Elo rating system: if a problem is solved by many people with average ratings, it means it is easy, so the problem rating should be relatively low; if it is only solved by people with high ratings, it means it is a difficult problem, so the problem rating should be relatively high. Specifically, the probability of a contestant with a rating of $x$ solving a problem with a rating of $y$ is $\frac{1}{(1 + 10^{\frac{y-x}{400}})}$. If the contestant and the problem have the same rating, the probability of solving it is 0.5.

We can practice problems that are 50 to 100 points higher than our own rating. Based on my experience, this difficulty is much more accurate than the difficulty given by Leetcode. Not everyone is equally good at every topic. For example, some people may be better at graph problems and can practice problems that are 200 points higher than their own rating, while others may not be good at bitwise manipulation and can practice problems that are 100 points lower than their own rating. The main concept is: practice in a place that is slightly more difficult than your comfort zone.

### Practice Method

Here is my practice method: Select slightly challenging problems based on the previous method to practice. Since these problems are slightly beyond your current ability, most of the time you should be able to solve them with some effort. If you still can’t figure it out after trying for a while (maybe one or two hours), you can look at the topic (algorithm) of the problem. If you still can’t figure it out, some problems have hints that you can look at. If you still can’t figure it out after looking at the hints, you can go to the discussion section to see how others have solved it. After understanding their solution, try to solve it again on your own and write down the problem. Try to solve it again in one or two weeks to make sure you really understand it and not just memorized the solution.

Even if you solve it on your own, you should still check the discussion section to see if there are more efficient or elegant solutions. If there are, practice that solution on your own as well.

## Premium Membership

Premium membership has two main features:

- Unlimited upload frequency.
- You can know which companies have asked this problem and some problems require membership to solve.

I don’t think it’s necessary to buy it. Even if I am sometimes blocked by upload frequency, I only need to wait for two or three seconds. My time is not that expensive. Normally, if I upload once and make a mistake, I need to spend some time to see where the mistake is. The chance of re-uploading within two or three seconds is not that high.

For the second point, because our goal is not to memorize every question but to have the ability to solve problems on our own. When we have practiced enough to have the ability to solve problems on our own, even if we see a new problem during an interview, we can still solve it on our own. And now there are more and more problems, so the chance of encountering a problem that has been solved before will become lower and lower.

## Coding Interview

There is one difference between coding interviews and writing algorithm problems: algorithm problems define the range of input so you can roughly know what time complexity algorithm can be used based on this range, but interviews usually do not provide this information. And during an interview you need to communicate your ideas with the interviewer; it’s not enough just to write down an optimal solution silently; so you still need to find someone to do a mock interview for you.

Basically as long as you can stably solve medium difficulty problems within interview time you will be able to pass most coding interviews. Being able to stably solve the first three questions (1 easy + 2 medium) within 40 minutes in a weekly contest is enough to pass most coding interviews. If you still can’t pass a coding interview it’s usually not because you couldn’t solve the problem.

Happy Leetcoding！