100-Day Daily Streak on LeetCode
Tags: leetcode, algorithms, programming
Published: 2024-01-31 18:16:01

I almost can't believe it's been 100 days of me grinding LeetCode! There was a point when I thought I completely lost my streak, and that point was 28th Jan 2024. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dippyahe42l3tnmiyhx2.png)

You see that gap in my calendar, that was the day our house was broken into and a lot of things were stolen, vandalised and ransacked. Before anyone complains about the semantics of that sentence I know ransacking is the act of stealing and vandalising, I am still in trauma so let me vent. The only way I could get my streak back was by using the time travel tickets.

As much as I would love to take you guys through all the details of the robbery, I doubt anyone is interested, so let's talk about what I learned during these 96 days (the last couple of days rolled into 1).

## 1. ALWAYS MAKE NOTES

LeetCode has this amazing feature that lets you take notes, especially when you submit a solution the notes panel pops up. This has been so useful for me to make my own notes as soon as I read the problem statement.

If it's an easy problem and the solution is obvious then I normally don't bother making notes, but for a bit more complicated problems my notes start off as a speculation of what approach I should use, then when a solution has been arrived I add to my notes what has changed. Some of my notes look like this.

```
A DFS approach would probably make sense here since we are looking for diff between ancestor and nodes
```

This note would evolve to something like.

```
[ Time taken: 24 m 46 s ] had the right idea but had a hard time converting it to code.

A DFS approach would probably make sense here since we are looking for diff between ancestor and nodes
```

## 2. Don't Rush Into Code

I would usually start the timer as soon as I started reading the problem. This put some pressure on me to read faster and start coding faster, but the more I got comfortable with the timer being on the more time I took to actually understand the problem better, go over the inputs and results until I could form some sort of a mental image. There have been so many times that it took me 10 min just to understand what the question needed and once that clicked, it would take me another 10 min to convert the idea into code.

Writing the code is usually not the hardest part, it's usually coming up with an approach that is hard. This is especially true for Medium problems, Hard problems are just there so you have suicidal thoughts.

## 3. Draw a Line in the Sand

In the beginning, I would spend more than an hour at a problem, write some code and keep on iterating on it until I passed more and more test cases. This is normally the approach most of us take when working on a feature request but it's not the best approach for LeetCode. A lot of times there is a trick that you are missing, or you are lacking a better understanding of the problem itself. At some point in time, its time to try a new approach or to watch a NeetCode video (no affiliation). My suggestion is about the 50 min mark you should probably change approaches and add that to your notes.

Don't let your ego get the best of you, be humble enough to know that your approach isn't working.

## 4. Know Your Language

I come from a JavaScript background, and although I have used Python at work for some reason I never enjoyed it as much as I did JavaScript. That is till I started the LeetCode75 study plan, and at that point I found out how many data structures JS is missing.

There were many times that I had the right approach in mind and managed to code the correct solution and then I discovered that Python has a much better way of doing something.

One thing I use all the time is `defaultdict` which when I discovered made coding up solutions much faster. 90-something days in and I am still discovering new ways in which Python makes writing algorithms easier. The more I use Python for LeetCode the more I enjoy it.

## Final Thoughts

While I am very far from being able to solve any problem that LeetCode throws my way, every time I do a problem I feel slightly more confident. The biggest issue I seem to have is in Dynamic Programming problems. Looking forward to making a new post with a 200-day streak.