The LeetCode Guide for Students
Intro:
Table of Contents
- Intro:
- 1. Pick a language
- 2. Build a strong foundation
- 3. Topics you need to learn to before you start solving Leetcode
- 4. Topics you need to be familiar with in order to make the most of LeetCode:
- 5. Start with “Problems”
- 6. Start fixing the problem at a high-level
- 7. Don’t try to solve random questions. Instead, go for “Curated Lists”
- 8. Zone of Proximal Development
- 9. You don’t need to buy the premium membership
- Lastly
LeetCode is a platform on which you can solve interview questions and read some other interview-related materials. Currently, it is one of the best ways to practice coding interview rounds.
It’s a huge repository of real interview questions asked by the most popular tech industries( Google, Amazon, Facebook, Microsoft, Apple, Quora, LinkedIn, Bloomberg, Uber, Goldman Sachs, Twitter, and others ).
The problem with LeetCode is that: students who have just begun learning Data Structures and Algorithms find LeetCode difficult to study: how do you start? What problems should you begin with? How many problems do you need to solve? Can a complete beginner jump into LeetCode - if not then what can he/she do to start solving LeetCode problems?
In this guide, I want to explain how you can start solving LeetCode problems, and how to make the most of this platform.
1. Pick a language
This guide isn’t about which language you should learn first. Most learners go with either Java/Python/C. The point is that you select one language that works for you.
2. Build a strong foundation
The number one reason why most students fail or quit LeetCode is that LeetCode has a prerequisite. I believe if you are completely new to CS, then you need to spend the first few months building a strong foundation before you register at LeetCode.
I’d strongly recommend that you study the following MOOCs (at least):
- Computer Science: Programming with a Purpose , or
CS50's Introduction to Computer Science
- Algorithms, Part I
- Algorithms, Part II
3. Topics you need to learn to before you start solving Leetcode
As I explained in the previous steps, there are certain topics that you must learn before you start solving LeetCode exercise. These are:
- Variables
- conditionals
- control flow
- loops
- arrays
- pointers
- scope
- hashmaps
- OOP
- Linked Lists
- Trees
- Graphs
- heaps
- queues
- searching algorithms
- sorting algorithms
- APIs
4. Topics you need to be familiar with in order to make the most of LeetCode:
- Backtracking
- Branch and Bound
- Brute-force search
- Divide and Conquer
- Dynamic Programming
- Greedy Algorithm
- Prune and Search
5. Start with “Problems”
Once you’ve built a solid foundation, you can jump into LeetCode, and start solving their problems.
Now, you’ll find that the problems are divided into 3 categories: Easy, Medium, and Hard. Of course, you should start with Easy problems. But, keep in mind, that this categorization can also be subjective: You might find one “Easy” problem to be “Medium”, a “Medium” problem to be “Easy”, and (worst scenario) find a “Hard” problem to be “Very Hard”.
In case you are completely new to LeetCode style exercises, I’d recommend that you start with the Easy problems.
When you are just getting started, the goal isn’t to find the “best” solution - but, to find “a” solution. The reason that I mention this is that eventually you can focus on optimization and increasing the efficiency of your algorithms. But, right now, your goal should just be: understanding the problem statement, brainstorming, forming a solution, creating the algorithm, testing and submitting your solution. Once you feel confident about your coding skills, you can try to create better solutions.
6. Start fixing the problem at a high-level
As you know, Programming isn’t just about code or syntax. It’s about problem-solving. When you encounter a problem, the healthy approach is to lay your hands off the keyboard, and instead, think about the problem at a high-level.
I highly recommend using The Seven Steps Technique for Translation from Problem to Code:
1. Work an example: work one instance of the problem by hand. You should not try to generalize to all possible parameter values at this point— simply solve one particular instance.
2. Write down what you did: The second step is to write down precisely what was done in Step 1. The most common way for novice programmers to get stuck at this step is to say “I just did it—I don’t know how.” In such a situation, you should work a slightly more complex example where the solution is not immediately apparent.
3. Generalize: You should generalize from the specific values you used in Step 1 to any values of the parameters. This step involves several components, such as generalizing specific values, naming values, identifying repetition, and making “almost repetitive” steps into uniform steps.
4. Test by Hand: Test your algorithm by hand. You should pick different values for the parameters that were not used in Steps 1–3 and execute the algorithm step by step with pencil and paper. If the answer is incorrect, you should revisit the generalization from Step 3.
5. Translate to Code: Now you are ready to translate your algorithm into code. Any step that is too complex to translate into one or two statements should become its own function: you can repeat the Seven Steps for that function and call it in this algorithm.
6. Test: Test the program, by running actual test cases on the code. If a test case fails, you can proceed to Step 7. If no test cases fail (and you have sufficient test cases to convince yourself that the code is correct), then declare success and be done.
7. Debug
7. Don’t try to solve random questions. Instead, go for “Curated Lists”
A big reason why people get “stuck” in LeetCode is because they might go visit the website, without any clear direction, and start solving random questions. Don’t do this. You’ll end up losing a lot of time.
You pick a random question, you start solving it, spend a lot of time, only to find out that this problem has test cases that haven’t been passed and it’s a question that no company actually asks.
A simple way to pick questions is by looking at the upvotes of a problem. Community members often upvote (or downvote) problems that usually indicates how “useful” and “solvable” a problem is.
You can select the Top 100 upvoted questions - that’s a good list.
Or, you can select problems from a Curated List.
Curated Lists are created by users who carefully prepared a list of problems that helped them crack an interview. There’s nothing wrong is solving LeetCode problems for the sake of learning or exercise. But, I understand that most of us are using LeetCode to upskill and move ahead in our professional journey. For that, it’s wise to find a curated list - created specifically for the goal you are trying to reach.
8. Zone of Proximal Development
The zone of proximal development (ZPD) is an educational concept which states that you can enhance your learning by working or studying something that’s slightly above your current aptitude. As you gain more competence, you are able to solve even more difficult problems. But, the condition is: you need to work on problems slightly above your current aptitude.
When solving LeetCode Problems, the natural state would be to solve as many easy questions as possible. I get it. Thinking is hard. And consuming. But, in order to gain competence, you need to solve more difficult questions. What’s more - you need to solve slightly more difficult questions. If you try to solve too difficult questions, you won’t be able to solve them, and you will lose the flow to keep learning.
That’s why - again - a curated list can be useful. A good list lists questions sequentially, guiding students from a low competence zone to a high competence zone.
(Completely subjective) Here’s a road map to solving questions of different topics, that can be done in any other order, but follow this one if you have none other:
Recursion -> Linked list -> Stack -> Queue -> Two pointers -> Sliding-window -> hashing -> sorting -> binary search -> trees -> BST -> Heaps -> Graph basics -> BFS -> DFS -> backtracking -> greedy -> Dynamic programming -> advanced graph -> Union find -> bit manipulation
9. You don’t need to buy the premium membership
This is completely subjective. I understand that there are perks of purchasing the premium membership, and if you feel it’s a better fit for you - then by all means go for it. In my opinion, the paid membership doesn’t offer enough benefits - meaning that the free membership is good enough for your goals. And, if you are a student, then I understand you have a limited budget. So, I recommend that you stick to the free membership.
Now, you will find “locked” problems that are only available to premium users. No problem. You can just google the particular problem (or even YouTube) and you will easily find the entire problem statement, as well the solutions.
Similarly, you won’t be able to see the solutions for certain problems (require a premium membership). In this case, you can head to the “discuss” page for that problem. Here, you will find a list of solutions and explanations by other users.
Lastly
LeetCode style problems have become a standard for many when preparing for new jobs and job interviews. They’ve been glamorized by some in the tech world, and they’re hated by others. However, practicing Leetcode problems of all levels has surprising benefits. It’s more than learning algorithms and data structures. Regularly practicing LeetCode problems can teach you process-related skills and enhance your skill set. Both of these benefits extend to your daily life and work, ultimately hardening your skills and improving the things you build daily.