How to use LeetCode without melting your brain
For those of you who are preparing for the so called “technical interviews” at any kind of coding position, LeetCode is probably your bread and butter. For the rest of the blissfully unaware folks, LeetCode (often abbreviated as LC) is a platform where people go to torment their brain … I mean to improve their programming skills.
LC is especially famous for improving the so called Data Structures and Algorithms (DSA) skills. What is DSA and why is it needed? Imagine this: you are a teacher who need to assign ranks to top 5 students in your class. This is a sorting problem, but also can be solved in a variety of other clever ways. Why would anyone want to be clever if a simple method would do the job? Well, now imagine instead of students in a class, the numbers represent the number of ‘likes’ of a set of posts on Facebook… and your app need to do this several times per minute. Suddenly the difference between a poorly performing algorithm and a fast one translates to a lot of savings in terms of API calls and cloud compute units.
For many aspiring software engineers, LeetCode is seen as a rite of passage – a challenging trial by fire that separates the wheat from the chaff. With its emphasis on solving complex coding challenges under time pressure, LeetCode can indeed feel like a pressure cooker for the uninitiated. However, with the right approach and mentality, LeetCode can be an invaluable learning tool rather than a hair-raising ordeal.
In this article, we look at a sample of opinions, stories and suggestions for acing LC problems. We focus on actionable tips as well as indulge in some vague generic ramblings, because we would like to give you the ability to to generalize beyond very specific advice. And at the end, we give several references where you can go to learn about DSA in a more enjoyable and in-depth fashion.
Let’s dive in!
Table of Contents
DSA are fundamentals of computer science
The key to surviving LeetCode is having a solid grasp of computer science fundamentals, especially common data structures and algorithms. While LeetCode problems may seem esoteric at first glance, most can be solved or optimized using standard techniques like arrays, linked lists, trees, stacks, queues, hash tables, sorting, searching, recursion, and dynamic programming. Knowing when and how to apply these basic building blocks is critical for efficient LeetCode solutions.
For example, linked lists are ubiquitous in LeetCode challenges. Mastering fundamentals like traversing, reversing, and merging linked lists in different contexts is a must. The same goes for essential tree algorithms like traversal, insertion, deletion, and sorting. And having a good handle on efficient sorting algorithms like quicksort, merge sort, and heapsort will enable you to optimize solutions when needed.
Beyond data structures and algorithms, having a good process is key to LeetCode success.
What is a process? Before diving into code, always read the problem description carefully and try some examples by hand. Figure out the inputs and outputs and consider edge cases. Next, think through a conceptual brute force solution and look for inefficiencies to optimize. Only then should you start coding.
While actually coding, resist the urge to over-optimize early. Get a working solution first, then think about improvements. Use good coding practices like descriptive variable names, modularity, and proper indentation. Include comments explaining your thought process and pseudocode if helpful. Verbally explain your code to reinforce understanding. That’s the goal – understanding, so you really want to write the code in a way that it makes sense to you when you review it three months from the time of writing it.
Make sure to test against the provided input/output examples first. Then come up with your own test cases, including edge cases. Fix any bugs before submitting.
What Does LeetCode Provide?
LeetCode is basically an online platform that provides a huge database of coding challenges to help prepare for technical interviews. With its timed contests, leaderboards, and paywall-locked premium questions, LeetCode gamifies the interview prep process. But what exactly does a LeetCode subscription unlock? Here’s an overview of LeetCode’s offerings:
Problem Database: LeetCode’s claim to fame is its massive bank of interview-style coding challenges. Their catalog contains questions across an array of categories like algorithms, databases, shell, concurrency, and more. Questions are ranked by difficulty from Easy to Medium to Hard, allowing for progressive skill development.
Solution Explanations: Most questions on LeetCode include detailed written explanations of optimal solutions. These explain thought processes, key insights, common pitfalls, time/space complexities, and suggestions for further optimization. Solutions are community-sourced from engineers around the world.
Discussions Forum: LeetCode has an extensive discussion forum where users can ask questions, participate in contests, and collaborate on solving problems. You can find hints, compare approaches, and gain insights from other users tackling the same challenges.
Contests: LeetCode regularly hosts timed coding contests with leaderboards to add competitive pressure. Contests typically last 1-3 hours and involve solving 3-5 problems. This simulates the time-crunched environment of real interviews. Both individual and team contests are available.
Interview Preparation Courses: For premium users, LeetCode offers multi-week guided courses focused on mastering specific technical interview skills like data structures, algorithms, system design, and behavioral prep. Courses provide structured schedules, video lessons, supplemental readings, and practice problems.
Company-Specific Questions: LeetCode has partnered with prominent tech companies like Google, Facebook, Amazon, and Microsoft to provide real past interview questions asked at those companies. This lets users practice on the types of problems they’ll likely encounter during actual interviews.
Mock Interviews: LeetCode connects users with experienced mentors for time-boxed mock video interviews. Mentors provide feedback and coach users on improving coding skills, communication, interview etiquette, and handling pressure.
Global Rankings: Users gain visible ranks based on LeetCode performance, adding a gaming element. Ranks motivate improvement and let users benchmark against peers worldwide. Scoring well can help land jobs at top companies that value LeetCode rankings.
Premium-Only Features: Paying LeetCode subscribers gain access to advanced analytics like submission history trends, tag filters, and leaderboard tracking. Additional features like offline practice, dark theme mode, and ad removal make the platform experience smoother.
In summary, LeetCode aims to provide everything tech professionals need to systematically improve technical skills and ace the interview game at leading software companies. With its enormous question bank, competitive elements, instructional resources, and built-in development tools, LeetCode seeks to be a one-stop-shop for interview prep.
How Should You Use LeetCode?
There is no definitive answer to this. You need to look at your current skillset, the skillset your future job requires, things like the LC quickstart guide, and chart a course for yourself.
Here are some helpful articles from people who have done just that:
- A Personal Guide to the Most Common and Useful Patterns for Solving Algorithm Questions
- Roadmap for learning DSA
- What’s the best way to use leetcode?
- 5 years of leetcode with no progress. I’m giving up
Is LeetCode Essential For A Programming Job?
Sort of. LeetCode type problems are a quick and objectively verifiable method of gauging someone’s thinking capabilities. However, those thinking capabilities may not correspond to the actual capabilities that are needed for software development.
But hey, that’s true for almost all tests isn’t it? We have known since decades (citation) that the standardized exams like SATs or GRE or others are somewhat lukewarm indicators of college performance. Yet, universities continue to insist on these grades because they are easy to compare and easy to calculate cutoffs.
Grinding LC problems can cause the side effect of becoming less effective at solving problems, what with practice with a hammer making all problems look like nails etc. Apparently interviewers can tell, as attested by this anecdote from Reddit:
I had my final interview for the Microsoft SWE internship role today, and something really stuck out to me. We were wrapping my last interview up after all the questions were done, and he literally told me “you aren’t like other candidates”. I asked him what he meant, and he said every candidate he had interviewed so far just grinds LeetCode and he could tell. He said that apparently, everyone comes into the interviews and just codes out the solution regardless of how difficult the problem is that he gives them, but as an interviewer he doesn’t actually know if they can code well or not, they could literally be copy pasting a solution that they memorized. He said no one talks their solution out loud, and doesn’t communicate their thought process or ask questions, and he is left with no clue of their actual programming capabilities, so he isn’t impressed by their solution. He also said that, maybe for other companies LeetCode might be good, but at Microsoft they aren’t necessarily impressed by it anymore.
I have no clue if I’ll get the role or not, but just thought that was an interesting tidbit to share. Just something to keep in mind, to talk through your solution and communicate way more than code, as that seemed to be what he was actually looking for.https://www.reddit.com/r/csMajors/comments/17vd61s/microsoft_interviewer_told_me_leetcode_is_bad/
When it comes to LC-style questions in interviews, Some people swear by it, while some people swear at it:
Some people are confident enough to consider letting their LC profile speak for itself:
Here are some articles and repositories that you would give you a leg up on your LC journey: