How to Get Better at LeetCode and Crush the Coding Interview

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hmm interesting move in your face hey guys welcome back to the channel sorry i got a little excited back there i finally beat grandmaster dylan at chess using a move called the scholars mate and today i want to teach you guys how you can be scholars too and destroy the coding interview by mastering lead code so the number one thing you can do to get better at these coding interviews and this is like the number one thing i can't stress this enough yeah i haven't said enough this is the number one thing what you want to do is go ahead and smash that like button and go ahead and subscribe so i can keep bringing you guys good content every week so you can become better software engineers and kill that code interview so i'll just decide how do you actually ace the coding interview well you need to get good at these lead code algorithm questions and one concern people often raise to me is they feel like that they can never get these problems they feel like they're doing these problems and there's they can do the easy questions but if they see a problem they've never seen before they have no idea what to do and then they're stuck so i want to show you guys today is my approach to weak code and how i was able to improve from the easy problems to solving most of the medium problems in just a couple of months i've only done around 200 week code questions actually a little bit less and i'm able to pass most of the coding interviews and so i want to teach you guys how to efficiently use the leak code to improve your skills instead of just grinding the questions and memorizing solutions so before i actually start i want you guys to know that this is a consistent long term project you can't just expect to just do this a couple of times when they suddenly become really good you need to do this consistently and over time you will see results so um what i like to do is i like to go on link code there's this kind of like challenge is the daily challenge and there's one of these every single month and i just go ahead every morning i wake up and i will do these problems right now i haven't actually done a lot of these because i've done i'm finished interviewing this year for internships and so i'm going to start back up sometime over the summer but during the recruiting season i definitely try to do one of these every single day and especially if you are still struggling with these problems it's really good start these problems because they're generally like more on the easy slash medium side and they give you if they help you be consistent while keeping you motivated so aside from that another thing that i do that helps to keep me motivated is to use this spreadsheet so i have this spreadsheet here where i have like the type of question that i do the difficulty so easy medium or hard and i have two categories that i sort them in the time it took me to actually solve this question and how fast the problem runs and so i have kind of this key on the right side here i see if i get if i solve this thing faster than 30 minutes then i give myself a green there if it takes me 32 an hour to solve it give me something yellow if it takes me over an hour if i don't even solve it at all i give myself a rep and um similarly with run i kind of have this like bucket system that i split these problems into and so by having these question categories on the left here and these um performance metrics on the right i'm able to kind of see which topics i'm not as good at and which topics i'm better at and that way and go ahead and see if i'm bad at something like a bit manipulation here i can go ahead and review that concept and improve my weaker points and so i feel like having that kind of a conceptual uh foundation is really important so this really helps you understand what things you're not understanding right now what things you are understanding and it helps you keep track of your progress over time so i think especially on top of the daily code challenges are a really good way to get started and keep yourself motivated and consistent while being able to see your progress over time okay so with all of that out of the way for the rest of this video i want to talk about the techniques i used for leak code in order to go from just solving the easy questions to being able to master the mediums and a lot of the heart in just a couple of months and so if you follow these techniques i'm sure that you will be able to improve your lead code algorithmic ability and this should translate and help you in the coding interviews so first off when i see a problem what i do is i need i read the problem very very closely uh sometimes two or three times and after that i kind of look at the examples and i make sure that i'm understanding exactly how this problem is operating because um you don't want to just jump in and write a bunch of code before you even know how to solve the problem you could be wasting a lot of time here and that also shows your interviewer that you're an immature programmer who's just jumping right in so you definitely want to be able to make sure that you're understanding the problem fully before you begin so the second thing i do then is i look at the constraints of the problem usually they'll tell you how big the input size will be and based off of that i can kind of analyze what type of algorithm i'm looking for so um for example um there's kind of like a list that you can go by most modern computer systems can do about like 10 to the power 7 or 10 to the power of 8 operations in one second so you should be looking for something that's in that range when you're coming up with your algorithm because you don't want this to be running very very long um so like a good rule of thumb to go by is if the constraint is 1000 so the maximum input size is 1000 your solution could be of n squared because that's like 10 cubed squared is going to be 10 to the power 6 which is 1 million so that's fine when you see 10 power 5 what i think of is n log n okay so i'm looking for n log n algorithm this could be like something like iterating with binary search or sorting anything like that that takes that n log n time so going up past that when you get to 10 to the power 6 um sometimes n log n will be ok for this but usually what if i get to an emphasize with 10 part 6 i'm thinking i need to find something that's little your time um and so this is just kind of like changing my mindset as i'm looking at this problem and obviously we do something super big i've had problems where the input size would go up to 10 to the power of nine if you have input scientific part nine you're probably not looking for something that's even linear time maybe a logarithmic time or even constant time sometimes like a little mathematical trick you can apply there that you can solve the problem in constant time so definitely be on the lookout for this input constraint and that can kind of help guide your mind towards what type of algorithm you should be looking for in addition to that you also should consider the space complexity so one thing i like to ask my dreamers what's very important in this case do we care a lot about space or do we care a lot about time in most cases we are pretty lenient with space and we are allowing us to use a little bit of space complexity there in order to improve the time but um it's good to kind of always ask your interviewer and know both sides of the solution like um take it take for example the problem two sum it's a very standard question and basically what it is is you're given an array of numbers that are in some arbitrary order you're given the target value and ask you are there two numbers in this array that sum up to this target value and so there's like two general approaches to solving this question one way is by using like a hash map or a dictionary and so you can just go through and you check for each number in this array you check if it's in the dictionary if it is you return true if it's not in the dictionary you put target minus that number into the dictionary and so that way you can solve this problem and line your time oven times because you're just iterating to the right once and over and space because you're having a hash map that in the worst case uh has all of these values in it so of and space and over and time but sometimes we could also be interested in constant space sometimes we don't want to use any additional space so another way of solving this problem would just be to like sort the array first and then use a two-pointer method starting from the beginning and the end if this sum is too big uh move the bigger pointer in words because um the numbers are sorted and if it's too small you move the other pointer and so if at some point this equals a target you return true if you reach the middle or the two pointers intersect and you haven't found it then you return false so in this in this situation the time complexity would be n log n because we sorted it but the space would be constant so um usually we kind of have like this space and time complexity trade-off and it's important to know most aspects of both aspects of this solution and so one way we co can help with this is that after you solve a question um you can go to the solutions section or you can go to the discussion board and there's a lot of people posting different solutions there and you can see how that time and space are traded and you want to go ahead and look at both approaches or however many approaches there are and just understand the techniques used here and understand that trade-off because that can be very helpful for interview so after you've come to this idea of um what time and space complexity you're thinking about using as well as understanding the problem fully you can start talking out loud so even when you're doing these legal questions you want to talk out loud to yourself why because when you go to the interviews whiteboard interviews or coding interviews whatever right you're going to be speaking to the interviewer so you want to be used to speaking and thinking at the same time so because it's actually quite difficult you've never done it before most people tend to do these problems just by sitting there and they just think about it on their own write some stuff and then they code it up but that's not very realistic so to kind of maximize the efficiency of using lead code you want to make sure you're just talking to yourself out loud as you're thinking of this solution and that'll kind of reflect onto the interview that's a really really important thing that you want to do there and so at this time as you're talking out loud you can kind of think about the pseudocode um it's really important that you come up with this basic idea first an interview because you want to explain to the interviewer what you are thinking and what your approach is before you actually start coding uh this is useful for a lot of reasons one um this shows the interview that you're actually thinking about this they can understand knowledge that you have another thing that this does is that this allows the interviewer to interject at times if they think that this is a good solution they can give you feedback you can also ask them you can think on you can say oh i'm not sure this is good how do you think this sounds um and so they're they're like yeah this sounds great they can you can just go ahead and cut it up um sometimes they'll be like i'm not sure this is the correct approach and so that can save you a lot of time of not going down this rabbit hole you can actually go and try to think of a different solution if the interviewer is kind of like guiding you along the way so it's really important to speak your thoughts as you're coming up with the solution and so you should allow yourself about 30 to 60 minutes for this entire process um coming with the solution reading the problem coding up the solution and if it's been over 45 minutes or 16 minutes and you haven't even done the solution yet it's probably not that efficient to keep trying here um it's probably efficient to go and look at the solution the discussion board see if you can understand someone else's solution and so there's a lot of different tricks out there you know solving these legal questions is kind of like accommodation math or competition programming but there's just like a test bank of questions that they kind of like just alternate and choose from after you've seen enough questions uh you basically have this kind of like two bank of skills that you know how to apply to these different questions and so by looking at these solutions discussion boards you can kind of understand the common techniques that people use to solve algorithm questions so next time you see a similar question on link code or like you see an interviewer interview question and you see you know similar you can then apply these skills that you've learned from the solution the discussion these tricks you can apply them to these questions and that can help you solve them so finally what i want to say is that be patient if you follow these steps you're making sure to understand the solutions at the end of each problem and what optimizations you can make eventually you will start to improve you will start to recognize those patterns and you'll be able to see oh this is a tree problem i should probably use a recursion so a lot of shared states your dynamic programming is good you know you're going to be able to see okay i've done this part of the problem before or i've seen this idea before how can apply it now and so that's going to be able to come to you more and more naturally over time and so you just want to do like a couple a day over a couple months and you will see significant improvement and i just want to kind of encourage people out there because i know it can be difficult um trying to learn these new concepts and gonna be frustrating but um i know this is a try and true technique i have a couple friends who aren't even computer science majors never did computer science before they just started getting these lego questions making sure to understand the solution fully and after a while they always get these great jobs from these really great companies and you know a big part of that is definitely because they're able to master this coding interview by practicing lead code efficiently and they haven't been doing this for years or whatever they've been doing this for months weeks and they've been able to improve a lot just by following these steps and being consistent and making sure you fully understand each problem before moving on so that's pretty much all i want to talk about today i'm going to make a video later on about top algorithms that you should know as a software engineer to help you crush the coding interviews but um if there's any other stuff you guys want to see please leave in the comments below i really appreciate it and i hope to see you guys next time and on another note i recently reached 100 subscribers so thank you guys for that really encouraging now i can keep bringing you guys great content
Info
Channel: Steven Qu
Views: 10,440
Rating: 4.7983871 out of 5
Keywords: LeetCode, SWE, Software Engineering, Computer Science, Coding Interview, Algorithms, Internship, FAANG
Id: KIPnfqNx5es
Channel Id: undefined
Length: 13min 25sec (805 seconds)
Published: Mon Feb 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.