My Approach to LeetCode

At the end of the day unless you are an algorithms and data structures genius you are going to have to put in a lot of time “grinding Leetcode”. But you don’t need to hate this process if you approach it with a healthy mindset and solid plan.

The Mindset

Leetcode problems don’t resemble real world programming tasks in the slightest. This has been repeated ad nauseum across the internet. Unfortunately, it is difficult to come up with a better system that would allow companies to figure out if a given candidate can do the job that they will be required to do in a cost effective amount of time.

Considering alternatives is the best way to quell the inner rage you might feel when asked these kinds of questions for an entry level dev job. The hiring managers could ask you to build something for them to a certain specification on your own time. This is worse as it is invariably going to take more time than a few tech questions. They could also simply look at school prestige and GPA but this would benefit people from wealthy families disproportionately and would most likely result in a lot of nepotistic hiring practices. They could look at personal projects but this is very time consuming during the initial weeding out phase of applications. All in all, asking a couple questions to filter applicants just makes sense and allows everyone to prove they have the ability to learn difficult concepts.

With that out of the way I highly recommend NOT thinking about the interview process when you are doing your Leetcode problems. Well, you should develop good interview habits like talking through your solution, planning before coding, thinking about base cases and edge cases, but you should also view Leetcode as fun puzzles.

If you aren’t aware every year there is an “Advent of Code” in December.

From Wikipedia:

Advent of Code is an annual set of Christmas-themed computer programming challenges that follow an Advent calendar. It has been running since 2015.

The programming puzzles cover a variety of skill sets and skill levels and can be solved using any programming language. Participants also compete based on speed on both global and private leaderboards.

https://en.wikipedia.org/wiki/Advent_of_Code

It’s a great time, there is a small narrative aspect and each day the story continues, the puzzles are just Leetcode style questions but Christmas themed. Everyone who does it enjoys it and you will learn a thing or two by the end of the month. Interview prep is exactly like this but without the theme/narrative. This shows it’s really the mindset you have that impacts how you feel about the process.

Stop thinking about interview prep as “a grind.” Grab a coffee or a tea and sit with your computer and notebook and use your beautiful brain to digest the problem. If you can’t figure it out no big deal, read the solution, take notes, and learn. If it starts to feel overwhelming or you start to get frustrated, take a break. Trust that you are learning, you are becoming a better problem solver, and all of this will be worth it in the end.

The Plan

Now that you’ve switched your mindset up let’s alleviate some more anxiety by creating a solid, actionable, plan. There are thousands of Leetcode questions but they are categorized in only a handful of sections. Luckily past nerds have created lists of high quality questions that introduce you to the major topics and solution patterns. The most famous would be the “Blind 75” (which you can google to learn more about) but the new meta is “Neetcode 150” which is a superset of Blind 75. Check it out here.

You can start with any category on Neetcode but I recommend starting from the top and working your way down. I also recommend doing all of the questions in one topic before moving to another. Now, if anyone knows anything about learning then you know it’s important to use spaced repetition and active recall to hold information for long periods of time but that will be the topic of an entirely separately blog post. Just know you will eventually need 1. a note taking system and 2. a review system.

Neetcode has easy, medium, and hard questions for each topic. Aim for 15 minutes per easy question and 30 minutes per medium. Also set upper bounds on each question, if an easy is taking you more than 30-45 minutes to solve you really need to just look at the solution. Once you understand the solution go back to the question and try to code it from memory. For mediums give yourself an hour. If you go through all the questions in a section and still can’t solve any in the allotted time, do some content review on the topic and go to Leetcode and sort by that topic and the “easy” tag.

What you will find is there are patterns for each topic so you need to learn both the question patterns and solution patterns. When you read a question you should immediately start thinking “this is a two pointer style question so I need to use maybe left/right pointer, or fast/slow pointer, etc”

As you go through more topics your bag of tools will grow and that’s a really good feeling. Suddenly you’ll be solving mediums consistently in under 30 minutes. The last step is to go to Leetcode and do questions at random so you can be sure you are able to recognize the type of question. Since Neetcode is categorized you haven’t necessarily been training that aspect of this “game”. But really once you know the solution patterns this will become much easier.

Conclusion

Leetcode and algorithm questions can be a daunting and overwhelming task for aspiring software engineers but with the right mindset and plan it can become a much more manageable and enjoyable task. It is important to remember to create a plan, take breaks, use spaced repetition and active recall to help with learning, and to keep pushing forward until you have mastered the material. With the right amount of effort you can be confident in your ability to face any coding challenge during an interview. Thanks for reading!

Print Friendly, PDF & Email

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *