How to use Leetcode effectively
Tags: algorithms, career, beginners, programming
Published: 2022-08-21 15:49:29

Ah fall semester, the season for internships/full time new grad roles. So if like me, you are preparing for interviews for big tech companies, I am sure you have come across [Leetcode](https://leetcode.com). If not, I highly recommend switching your preparation from other platforms to Leetcode(and sticking with it). Leetcode has a large collection of questions, great community written solutions to problems and an awesome discuss section.

If you are just starting out consider checking out my [Leetcode Survival guide](https://dev.to/dfs_with_memo/leetcode-survival-guide-1cp3) so that you don't waste your time solving random Leetcode problems or buy expensive courses to learn data structures and algorithms.

In this post, I will write about how to use the different features available on Leetcode for interview preparation. Be its your first time interviewing or you are a seasoned interviewer, I am sure you may not have come across all these features or you are not using them.

The post will contain two sections, one aimed at all users and another section for those who have purchased Leetcode Premium(LC Premium). You can refer to the table of contents to jump to any section

## Table Of Contents
  * [For everyone](#e)
    * [Discuss section for solutions] (#1)
    * [Discuss section for interview experiences] (#2)
    * [Daily leetcode problem] (#3)
    * [Input size] (#4)
  * [Premium users](#p)
    * [Problem with sorting by frequency] (#5)
      * [Filtering by topic and company tag] (#6)
      * [Company specific list] (#7)

## For everyone <a name="e"></a>

### Don't ignore the discuss section for solutions <a name="1"></a>

Once you submit your solution, Leetcode shows how your solution's run time compares with all the previously submitted solutions. Now, the runtime of your code is very much dependent on how loaded the servers running your code are. So it may not always be accurate. To get an estimate of your actual performance, you might have to run your code several times. 

If on your first try you get a solution that is just 5% faster than all the solutions, don't expect to get better than 20% faster than all solutions at best. At this point, I suggest you check out the discuss tab for the problem. You might have written a non-standard solution or you might have to tweak some part of your code. 

For example - you might be mutating strings in Java without using the StringBuilder class, you are passing many parameters into a recursive function call, you are using a heap when in reality a queue would have sufficed and many other factors. So head out to the discuss section and you will find concise(and more performant) ways to write the solution.

**If your solution beats most of the solution, I encourage you to write a post which will help others on their way. Typing up an explanation will help as well. Make sure you use an appropriate heading and provide the correct tags.**

### Don't ignore the discuss section for interview experiences<a name="2"></a>

Regardless of whether you are a premium or free user, you should check out interview experiences by other users. Why? Two main reasons:
1. It will help you anticipate the format of your interview(OA, phone screen, on-site, HR/team matching rounds, compensation)
2. You might stumble upon a question that is not even present on Leetcode.

Not every post would be well detailed. I would suggest going through multiple pages in the search result and collecting high quality interview experiences and storing them in an excel sheet. I personally use [Notion](https://notion.so)

### Don't ignore the daily Leetcode problem<a name="3"></a>

The daily Leetcode problem is a great way for newcomers to experience different types of problems. Even if you don't solve the problem entirely on your own, I would suggest reading the problem, thinking of an approach and if you can't come up with one, check out the discuss section. 

**I would advise not developing this urge to solve each and every daily problem. If you feel overwhelmed by the problem/solution be focused on your interview prep. There's no harm if you are unable to solve the problem because it's too difficult. If the problem is good and you want o visit it later, you can add it in an excel sheet or have your [Custom list](https://support.leetcode.com/hc/en-us/articles/360013577094-How-to-use-My-List) on Leetcode.**

### Don't ignore the input size<a name="4"></a>

When you read a problem, the input constraints are always mentioned at the bottom. Make it a habit to read it for every question and it's a good practice to clarify with your interviewer. 

Why? Because the input constraints is directly correlated with the time complexity of an accepted solution. There has been many a time when I have thought of a solution that would work but I didn't code it up and try because I thought my solution would give time limit exceeded(TLE). I would then go to the discuss section or watch a video and it would feel frustrating when I see the same solution.

Here's a table that maps the time complexity with input sizes

| Input size   | Time complexity   |
|--------------|:-----------------:|
| >= 10^5      | {% katex %}O(n) / O(nlogn) {% endkatex %} | 
| 1000-5000    | {% katex %} O(n^2) {% endkatex %}         |
| 100-500      | {% katex %} O(n^3) {% endkatex %}         |
| 0-32         | {% katex %} O(2^n) {% endkatex %}         |
| 0-15         | {% katex %} O(n!) {% endkatex %}          |

Generally speaking, the above relationship is applicable to common platforms such as Hackerrank.

**You can use the input constraints to come up with an algorithm. For example: if you see a problem with the constrains 0-32 consider applying bitmasking dynamic programming**

## Leetcode Premium users<a name="p"></a>

I advocate purchasing the Leetcode premium subscription for a year. It makes life easier. Sure you can access the premium problems on other websites and dig up previously asked questions for a company from a variety of forums and sources but LC Premium just hand waves all these issues. 

**I don't recommend buying LC Premium as you are starting out. There are already a lot of high quality problems that are available or free and are asked in a lot of companies. Once you have finished 150-200 problems and you have interviews lined up in the coming weeks, I would recommend you to buy LC Premium**

###The problem with sorting by frequency<a name="5"></a>

One of the best features of LC premium is being able to sort problems by their "Frequency". But it's a double edged knife. 
The frequency that you see on the all-problems list, is actually not the number of times the problem has been asked in the past 0-6 months, 0-1 year or even 1-2 years in the past. Leetcode has their own algorithm to calculating their frequency. 

Here's a [post] (https://leetcode.com/discuss/feedback/1912580/answered-leetcodes-lists-and-frequency-counting-feature-seems-broken) (credits to a friend of mine for the link) in the discuss section about it.

I personally don't agree with Leetcode's logic on this. I believe that the best way to prepare is to solve the most recent frequently asked questions(in terms of count).

There are two ways in which you can go about doing this.

####Filtering by topic and company tag<a name="6"></a>

You will need an excel sheet for this. Navigate to the [all problems page](https://leetcode.com/problemset/all/). Chose the topic for which you want to know the most frequently asked questions, say DFS and then chose the company. Click on the frequency column to sort by "most frequently asked problem". Now, here comes the tough part.

Click on the problem to open the problem in a new window. Scroll down to the end and there will be a companies tab, expand it and you will see the frequency count. Refer to the screenshot below.

![Expand the dropdown](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xymzz3ocyspms7oglxs0.png)

This is where you will find the actual count. Copy the problem link and note the frequency. When you are preparing for an interview solve by the highest to lowest count. I would advise clicking on each and every problem in the first page and pulling out the frequency count into a separate sheet.  

#### The company specific problems list<a name="7"></a>

I find that this is approach to be slightly more reliable but it's difficult to prepare topic-wise. 

Navigate to the [all problems page](https://leetcode.com/problemset/all/) and check the bottom right side right below the calendar. 

![Company specific tag](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xlqpw2f7coq6v7hgkrw3.png)
 
There is an option to search for a company. Search for the company you want and click on it. You will be directed to a view that looks like the screenshot below.

**Pro tip- you can quickly navigate to this view if you type 
https://leetcode.com/company/google/ you will be navigated to the problems asked at Google**

I would recommend first solving the problems in the range 0-6 months by their actual frequency count using the method described above.

## Conclusion

I have followed these steps to improve my chances of clearing interviews and I hope you have learnt something new today.

I appreciate any comments, thoughts and feedback on the article.

Till next time, I wish you good luck on your prep.