How I tackled over 600 LeetCode problems, and here are my recommendations.
I want to tell you a story about how I started from the level of "can't solve even 1 easy problem out of 10" to the level of "can solve every other medium problem" and went through several coding sessions at companies like Meta, Booking, Careem, Avito...
It all started at the end of 2022 when I firmly decided that I wanted to land a job at a FAANG company. However, as you probably know, this requires knowledge of algorithms and data structures, which I lacked because in regular work, you don't need heap, tree, disjoint set, and other data structures. So, I had to start almost from scratch.
It was very challenging since I didn't know where to begin, how to approach problem-solving, what was important, and what wasn't. I also had questions like how many problems to solve to feel confident and if I could even progress to medium-level problems. Solving even easy problems was puzzling, and below, I'll try to help you with this.
The first thing that comes to mind when you want to start solving LeetCode problems is to open the problems page https://leetcode.com/problemset/all/ and start solving them sequentially. However, it's not a great idea, even if you filter for easy problems, because many tasks labeled as easy are quite challenging. This can be demotivating and even lower your self-esteem.
Tips:
First tip - pay attention to the Acceptance rate; the higher, the better. This indicates that many people manage to solve the problem, increasing the likelihood that you can too. Additionally, you can explore the study plan and try solving problems from there:
Top 100 Liked: A list of highly liked problems. If there are many likes, there's a chance it's not a convoluted problem that could lower your assessment.
Top Interview 150: A list of the top 150 problems for interview preparation. You're likely to encounter these in interviews, but some might be challenging, especially early on.
LeetCode 75: Described as a "Must-do problem list for interview prep." These problems are categorized into different topics; solve them following the next piece of advice.Second tip - start with the most fundamental data structures like arrays (one-dimensional/two-dimensional), set, hashmap; you'll encounter them frequently. For instance, in many problems, execution time can be improved by adding a set or hashmap (though keep in mind this may increase memory consumption). Only after mastering these should you delve into other structures like stacks, queues, linked lists, trees, and graphs.
On LeetCode, there are cards providing explanations of data structures and algorithms, along with problems to reinforce these concepts - LeetCode Explore. As mentioned earlier, begin with simple cards like arrays and strings, gradually increasing difficulty. I revisited these cards several times because some concepts weren't clear initially. Don't think there's anything wrong if something is unclear; return later, and you might find you now understand it.
Here are some additional resources:
LeetCode Learn: Cards with explanations and problems.
Neetcode Roadmap: A roadmap with topics and problems; highly recommended.
Tech Interview Handbook: Create a weekly plan using various filters.
LeetCode Patterns: A list of 150 popular problems categorized by topics, difficulty, and companies.Third tip - if you can't come up with an optimal solution, start with a "brute-force" solution. Once you have that, think about how to improve it.
Can you use a specific data structure?
Can the array be sorted?
What if you use a set or hashmap?
Is there a template you can apply?
If nothing helps and you've already spent 20-40 minutes, confidently open the solution and study it. After doing so, close the solution and try to solve it again (this may take several iterations, which is normal). If you're still unable to solve it after multiple attempts, consider typing out the solution (I've done this several times). However, don't forget to revisit the problem later and try solving it again. It's entirely possible that you might not succeed initially, and that's okay. Just repeat the steps until you're confident.Fourth tip - go through these 14 patterns, especially focusing on two pointers, sliding window, and fast & slow pointers, as they are often encountered. Take a pattern, find problems under that pattern (on the LeetCode problems page, use the filter for tags like "Two pointers" or "Sliding window"), and solve enough problems to solidify your understanding of that topic.
Fifth and most important tip - practice, practice, and practice again. In the beginning, I often felt like crying from frustration because I couldn't even solve simple problems. This is not an exaggeration. The thought of "I'm so dumb" lingered in my mind for the first few months. Even after solving 600 problems, there are still moments when self-esteem drops, especially if I can't solve a seemingly easy problem. What's important is that with each solved problem, you'll become better relative to yourself.
Solving LeetCode problems is now addressed on the platform Firecode, where problems are presented one after another, starting with easy ones and revisiting previously solved problems for reinforcement. There are explanations for various topics, and after solving a problem, you can see how others approached it, which is very helpful for understanding different solution strategies.
FAQ:
What should I do if I can't solve a problem?
If you can't solve a problem after 30-40 minutes, look at the solution, try to find a video solution for that problem. After reviewing and understanding, attempt to solve it again. If unsuccessful, repeat the process. Periodically revisit old problems, especially those that were challenging. I've sometimes solved the same problem 10-15 times or more.
How many problems should I solve before applying to jobs?
It varies individually. I spent six months solving a few problems every day, around 300 problems, before feeling a solid foundation. Confidence came after solving around 400-500 problems. Some may only need to solve 100-200 problems, but unfortunately, I'm not among them.
Which programming language is best for problem-solving?
In short - Python. I started with PHP, switched to Go, then Java. After watching a video, I tried Python and have been using it since. Python's concise code, built-in functions (like Counter, defaultdict, divmod, lambda, etc.), and speed are advantageous during interviews.
How to find time for problem-solving?
I aimed to solve two problems daily, one before work and one after. On weekends, I dedicated more time, watching videos, reading articles, solving more problems, and revisiting old ones for reinforcement.
Is it worth buying LeetCode premium?
The most useful feature of premium is seeing which companies gave a particular problem. If preparing for a specific company, it's recommended; otherwise, the free version is sufficient. Video explanations can be found on channels like Neetcode.
Is it worth buying access to educative.io?
While there are many recommendations for the Grokking Coding Interview Patterns course on educative, I didn't find it very useful. Visual explanations were the only positive aspect. In my opinion, watching YouTube videos is a better alternative.
Is it worth buying access to algoexpert.io?
In my view, algoexpert.io is a very useful resource. Each problem comes with detailed explanations in videos lasting 30-50 minutes. They often have promotions, and you can sometimes get all courses for a year for $99. It's reasonably priced, has a pleasant website, numerous test cases, and a user-friendly editor.
Results:
- Achieved my initial goal for solving algorithms - passing coding interviews, a crucial step in FAANG companies. Successfully went through several interviews, and most importantly, no longer fear this stage.
- Deepened understanding of data structures. From not knowing what a heap is, I now have a comprehensive understanding of this structure and others.
- Changed my perspective on code during work. Now I can identify areas to use more memory efficiently or reduce time complexity.
- Last but not least - brain fitness. Transitioned from "don't want to do it" to "want to solve problems every day."
Useful Links:
- NeetCode YouTube Channel - Possibly the most helpful channel where concepts are explained in an accessible way.
- William Fiset's YouTube Channel - Many useful videos explaining various data structures.
- BackToBackSWE YouTube Channel - Explains data structures and problems on a whiteboard.
- Inside Code YouTube Channel
- Geekific YouTube Channel
- Michael Muinos YouTube Channel
- Nick White YouTube Channel
- TechLead YouTube Channel
- Coursera - Algorithms Part 1 (Russian) - Many recommendations; I haven't personally taken it.
Russian version: https://habr.com/ru/articles/786184/
Top comments (2)