How would I grind leetcode if I could start all over again? I'm going to try to make some points that are honestly pretty simple, but I think you probably haven't heard most of them before. And quickly, before I start, someone always comments, leetcode is useless, save your time doing real development, blah, blah, blah. It's completely true.
I've never encouraged people to grind leetcode. I've only like told them how to do it. It's true that most full stack jobs don't require knowledge of data structures and algorithms. I would still personally argue that DSA knowledge is still useful, at least understanding like the core algorithms.
But you know what else is true? You probably went to school for 20 years of your life learning a lot of things that you aren't going to use at your full time job. That doesn't mean learning those things was useless. From my perspective, if spending a couple months grinding leak code.
can get me a really high paying job, then honestly, I don't care how useless it is, because LeetCode literally changed my life. Even if I didn't create like the YouTube channels, the fact that I was able to get a job at Google, just because I grinded LeetCode seems pretty worthwhile to me. And I think it's a life changing job for most people.
But how do you actually get good at LeetCode? Let me explain. When I first started doing LeetCode problems, I realized this is the most academic academically difficult thing I've ever done in my life. I had taken AP calculus and physics and a bunch of really difficult things in high school and in college.
Honestly, college for me was a little bit easier than high school. I remember everyone would always say, you know, high school is hard, but wait until you get to college. College is going to be really hard.
That's when you're going to have to learn how to study and improve your study habits and everything. For me, I think when I took my first programming class in college, that's when I struggled a little bit. But after that, at least for me, I went to a pretty average college.
It was relatively easy. I'm not going to lie. But you know what was difficult when I started hitting leak code problems? I wish somebody had told me, you know, leak code is not easy. This is the hardest thing you're probably going to do to get a job.
It's going to be harder than all of your classes that you've ever taken. When I took my first programming class, like I said, I struggled a little bit at the beginning. So for me, programming is actually harder than these other technical subjects. But now I tell myself I was just in that like machine learning phase where I was just taking in a bunch of new data, understanding how to use it.
And then eventually I got familiar with it and then I was good. I wish I could say the same thing about leak code. Every time you think you're good at it, you see a crazy problem and it just destroys your confidence. It's completely different than anything you've ever seen before. So what is so different about leak code than everything else?
Is it really harder than everything? Like when I was doing it, I just thought, damn, I guess I'm just not smart enough. I thought I was a genius my whole life doing everything so easily, getting A's whenever I wanted to.
But damn, this thing, I just can't do it. I don't think it's about intelligence at all. Believe it or not, it's about systems. It's about processes. It's about methodology, how you're doing it.
At least that's my opinion. And I'm going to try to convince you why. First, let me show you how I learned.
LeetCode when I first started. You have a problem, a hard problem, median of two sorted arrays. It's the fourth LeetCode problem. Imagine how many people came across this problem and just wanted to jump out the window after.
Of course, most people can't solve it. So what do you do? Well, back in the day, LeetCode didn't really have articles and editorials, and even this one is paywalled.
So you end up going to the solutions tab. It used to be called the discuss tab. Nowadays, if you go here, you'll click one of these and man, you'll see this. beautiful explanation. Look at this.
This guy's explaining it with hints, with everything. Doesn't have any pictures in here, but sometimes they even have pictures. You know, it's reasonable to be able to understand one of these solutions.
You can see this one was recent, right? 2023. Back in my day, though, we didn't have that. This is what we used.
We used these solutions. And also Lee215, if you've heard of him. But look at this.
Like, look at this solution. First of all, just look at it. Crazy solution.
And not much of an explanation given. Okay, the second one is, I guess, a little more reasonable. I don't know. Even though the third one is definitely a little bit more reasonable, there's not really much of an explanation.
You go down here, you don't see much of an explanation, at least back in the old day, like 2019, when I was doing it. Everybody's just asking, can you actually explain it? And nobody did.
Okay, the best you'd get is like five comments here. So I know I make videos on these problems and sometimes I don't do a perfect job either, but you have to realize that it's tough love. Okay. I can't explain every little detail in a 20 minute video.
I can do the best to give you like the intuition of why a solution works. Even that, in my opinion, is a lot easier than how I learned. This is how I learned. I would look at these solutions, you know, for hours and hours, try to figure out why they worked. And finally, when I did, I would try to make like a.
video explanation for it. Thankfully, now we do have a lot better resources. But even then, leetcode is still not easy.
Why isn't it easy? So if I'm arguing that leetcode actually isn't much more difficult than math or physics or some other highly technical subject that you have learned before, why does it feel so much different? And I think one big reason is the process, the methodology, the way that you learned these things.
versus the way that you're trying to learn this. Let me just kind of rewind, take you back through time and remind you, how did you learn math when you were a kid? You probably first learned how to count like one, two, three, four, and just learned the base 10 digit system.
And then you probably learned bigger digit numbers, 100, 110, 234, something like that. And you were able to then start adding numbers together one plus two. and then bigger digit numbers, 3, 4, 5, 1, 2, 3. Do you think if I successfully explain to a child how to solve this problem, and they are able to do it, they are able to take these digits and add them together and get that big number, and then I make it more complicated, and I teach them how to carry a number to do like more complex addition, maybe subtraction. If I show them how to do that just a single time, or maybe even several times in the same day.
And then maybe a week later, a month later, I show them the same thing and they don't practice in between that week or month. I give them a similar problem. Do you really think they'd be able to solve it? Probably not unless they're really, really smart. The point I'm making is you could teach somebody how to do something difficult.
They do it a single time. They think they understand how to do it. But if a bunch of time goes by, you're probably not going to be able to do it again. Kids learn the same way adults do with repetition, right? So.
That's a pretty simple answer. Repetition. So why don't more people do it? I mean, it just sounds so simple. Why don't more people do repetition when it comes to leak?
Let me kind of explain the classic problem people make when they solve leak code problems. Let's say they're solving a medium binary search problem. And I bet you most people who try to solve a like medium level binary search problem, they're probably not even super good at like basic binary search, but okay.
They try to do it. It takes them probably some cognitive energy to even implement basic binary search. You know, if it takes you 10 minutes to implement basic binary search, that's a problem. You shouldn't even be attempting medium problems. If it takes you, you know, 10 minutes to figure out that this number is 234, why are you doing addition?
You don't even know what this number represents, right? You got to get really, really good at the basics before you kind of take steps beyond that. But okay, just continue. You get to a medium binary search question. You realize that it's a binary search question, but you still can't solve it.
All you have is your basic binary search algorithm implemented. Then you look at the solution. It takes you maybe one hour to understand the solution, but you're able to do it. You write your code. You kind of really exercise your brain muscles.
You write it and now you're done for the day. Then you continue solving problems. Maybe a month later, you solve another medium binary search question.
You're not able to solve it. You look at the solution. It takes you some time to figure out the solution. Once you realize it's binary search, you feel bad. You realize it's similar to a problem you've already solved, but you weren't able to figure it out again.
Why not? Because you tricked yourself. You think you understand the solution, and maybe you did for a very short time, but that didn't really sink in.
And it's not your fault. When you're learning something that's genuinely difficult, like if you're reading the solution to a problem, it's difficult, and you think you understood it, which you might have, but it didn't sink in. So of course you need repetition. It's such a simple answer.
Isn't it just practice? But then why isn't anybody doing it? This is how you learn pretty much everything in life.
When you learn how to read, it takes practice. Why don't people do it when it comes to leak code? I don't know, but let's be honest. I made the same mistake until I realized this.
I thought like, huh, I did so well in high school. I did so well in math and physics. So why am I so bad at leak code?
Because the way I'm practicing it isn't enough. LeetCode is difficult. It's difficult like math and physics, but it's not more difficult. You could not teach somebody how to count and add numbers and divide numbers in a relatively short time without practicing. So now let me try to give more concrete advice on how to practice, how to actually do repetition, because even that isn't as straightforward as you might expect.
First of all, there are certain core algorithms, algorithms like... binary search, DFS, depth first search, breadth first search, sliding window, and a bunch of other kind of core algorithms that I talk a lot about on this channel, as well as like, you can check a lot of this stuff out on neatcode.io. But My personal advice to you would be get really, really good at these basics.
Practice them a lot. You can do that at the same time that you're solving leak code problems, or you can do it before you start solving leak code problems. But you want to get good at it.
And I promise you, it won't take you that long. The target that most people set when they're solving leak code problems is I want to be able to look at a leak code problem and solve it quickly. That, in my opinion, is the wrong target.
You should get really good at just core algorithms. That should be your target. At least that should be your first target.
And binary search, it's a very short algorithm. What is it like less than 10 lines of code? I think every computer science student learns that maybe the first time you do it, it'll take you like 30 minutes or an hour to like fully understand it. Okay. The next time you implement it should probably take you like half that 15 minutes.
The third time you do it, I bet it'll take you like 10 minutes. And the fourth time, probably like eight minutes. eventually you should get to a point where you can implement this in less than five minutes.
I could probably do it in like 30 seconds, to be honest, because it's not that much code. You could say I memorized it or you could say I deeply understand it. You could say whatever you want. But the point is, I could implement it very quickly. So now when I get to a medium difficulty leak code problem, the binary search aspect of that problem is trivial to me.
It's like one, two, three, like a number systems. It takes me no cognitive energy to focus on. implementing binary search or understanding why it works, understanding why it's efficient.
Any of that doesn't take me any time to get to this level. Suppose it just takes you like implementing binary search five times. And I probably implemented it, you know, dozens of times, but there is like diminishing returns. If you can implement binary search 10 times in the period of like a week or a month, you can probably get just as good at it as I am. Some of these other algorithms are probably a little more difficult DFS BFS, but the same idea can be applied to those implement.
these five times, 10 times, whatever, it'll probably take you a few hours to do that. Let's say four hours to implement it like 10 times. Now you don't understand you have such a big advantage when you look at leak code problems now, like you really don't understand it until you've experienced it.
And when you've been in my shoes, many of you who are good at leak code probably know the feeling. These things are so trivial to you that medium problems can also be a lot easier. Now you actually have the brain capacity to focus.
on how you can take these algorithms and actually apply them to a medium problem, which takes a lot of energy. You're not kind of juggling two things at once. You're not trying to re-remember how do I implement BFS?
And also how do I apply it to this difficult problem? You're not doing that. I don't know why when somebody solves a leak code problem, and then they look at the solution, they feel bad about that, but they look at the solution, they're able to solve it.
Why not solve the same problem the next day? Why not? Do you think you're going to lose anything by doing that?
I guess it takes time. But if that problem is fresh in your mind, it might not take you more than like 15 minutes. So why not do it? You're reinforcing something that is good.
I promise you anybody who's really, really good at leak code or a really good competitive programmer, this stuff is literally like ABCs to them. You have to do that to get good. You can call it cheating. You can call it memorizing, but that's just how it is. And I know for a lot of people, this isn't fun.
But in my opinion, it's pretty fun being able to go into an interview and be able to solve it and then get, you know, a high paying job as a result. Even if you agree with everything I've said so far, there is some more nuance to this. Leak code is more difficult than just what I've talked about here. Some problems are definitely more difficult than just taking something and applying like a core algorithm to that problem.
I'm specifically talking about hard problems and even some medium problems. I think the next level of getting good at this stuff. is similar to what I'm talking about, repetition practicing in a smart way. But I think the next level is asking the question, why does something work? Most people think math is just memorizing, memorizing numbers, formulas.
You have some formula, F equals MA in physics. Once you know what the force is, the mass is, the acceleration is, you just take those values, you plug them in, and then you get some value as a result. That's what people think math is.
What math really is, is being able. to argue why the math works in the first place, aka proofs, right? You might have taken a discrete math class in college or some other class where you had to do math proofs. And this is kind of that second component to leak code problems. In my opinion, the more complicated component, you might have looked at a leak code solution or watch one of my videos, even though the algorithm made sense, it might have been an algorithm you're familiar with, you still didn't fully understand why it worked.
And the why is so important. important because if you want to be able to solve a problem for the first time, you have to really understand why the repetition I talked about before will only take you so far. What I'm getting at is it's not just about. being able to quickly write out the DFS algorithm or BFS algorithm from scratch.
It's about understanding exactly why it works. I try my best in my videos to explain this, but it's not always easy unless I want to make like an hour long video. My advice to you for figuring this stuff out is just spending some time thinking about it. I know that's kind of an obvious answer, but it's the only answer. Nobody can force you to do it no matter how well of a resource you find, whether it's an article or a video, nobody can go in your brain and actually force you to think about why something works.
And you do need a little bit of curiosity for that. For example, there is an algorithm called two pointers. It's applied in many cases to like binary search. You need two pointers and in sliding window, you need two pointers.
And there's a condition in problems where you'll have something like while the left pointer is less than the right pointer. This is the condition. Sometimes, though, you'll have the condition while left is less than or equal to right.
And I've had some people ask me the question, how do you know whether it's this or whether it's less than or equal? And they try to memorize it. But I don't think it's worth memorizing.
I think you have to really look at the context of the problem and figure out why that's the case. The easiest thing would be to come up with some examples. I think.
people watch my videos sometimes because I'll have like an example and walk through it. Why can't you do that by yourself? Why can't you bring out a pen and paper and just walk through an example by yourself? Is it because you're lazy?
Because I promise you, I wouldn't have gotten good if I didn't do this drawing. And I only do the drawing for my videos. When I'm practicing something by myself, I'm using pen and paper.
So if you're the type of person, when you get stuck, you just kind of go blank. You just stare at your screen. You're just thinking in your head. Try to do something else.
Try to... to type out some notes, some comments as you're trying to code up a solution or, you know, use pen and paper. If you're not doing that, you're missing out.
I promise you anybody who's really, really smart only got good at it by practicing, by thinking of creative examples, by thinking of edge cases that would maybe break a solution or maybe would reinforce a solution and explain why exactly that solution works. I think if there's anything that you have learned from this video, it's that a lot of the things you did as a kid. and maybe you stopped doing as an adult were very, very useful to you, like taking handwritten notes, explaining your thought process, repetition, even boring repetition, even doing something so many times to the point where it just gets so boring.
That's kind of what math class was as a kid. Those things are useful, like the structure that is forced on you when you're a kid is very, very useful. And I think having too much freedom as an adult is not when you have like eight hours in a day, it's easy to procrastinate. But when you're a kid.
you have like one hour with this class, a second hour in Spanish class or whatever. And that kind of structure is pretty useful when it comes to learning. There's a reason why everybody does it all around the world.