How I choose the next leetcode problem to solve
Do you just pick an arbitrary problem to solve or have some systematic approach to that?
I generally do it both ways.
- I pick the tasks at random, using an Anki deck (described in this article) and also
- I pick the tasks with the lowest solved/total ratio
The latter approach I will describe here.
I like solving leetcode problems by topics. It helps you concentrate on a certain type of problems. After solving 5–10 problems on a given topic, you usually:
- Developing your own template for this type of problem which helps you later to code faster and concentrate on the whole solution rather than the details
- Start noticing a pattern. Later, when you see other problems, you might notice that you start recognizing those patterns behind the descriptions of the problems. If you jump from one topic to another, it is much harder to learn those patterns
But unfortunately, on leetcode, there is no straightforward way to say how much progress you have made on the particular topic.
I use my own for that.
To generate such statistics, you have to follow a few simple steps.
First set up a virtualenv
Then in python shell (or file) initialize the client
Now once the client is initialized, you can start performing actual queries. Let’s try to write some code to calculate the necessary statistics.
First of all, we have to acquire a list of all the problems we solved.
Now for each problem, we want to get its tags.
The output will look like this:
So it is clearly visible which topics we should focus on in our preparation. In this case, the memoization topic is one of the targets for improvement, so I can go to and choose a new memoization problem. Or use python to automate the process.
Well, and this is how I do that. You can use this API for many purposes, and what I just showed is just one of the simplest things you can achieve. I hope this article finds its reader, as I’m pretty sure there many people out there who want to automate their leetcode grinding workflow as well.