How to Solve Coding Problems (the best way to learn)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay tell me something does this sound like you you watch programming videos you feel like you understand everything and then when it comes to coding yourself you just draw a blank you can't do it videos and courses are great actually but they only get you halfway there you're gonna need a lot of practice to actually become a programmer i'm going to show you how to start solving coding problems in this video by the way i'm aaron jack remote software developer if your dream is to become a remote software developer too that's what this channel is all about so consider subscribing all right what's the best place to start solving basic coding problems well when you're starting out you want to go to code wars and that's going to be codewars.com you can just make an account and then have access to all the problems which you get um here in the sidebar you go to kata then you filter by 8 kyu which is the easiest difficulty and there's 49 you can just start doing here these easy problems are still going to be pretty challenging for beginners but hang in there you'll get better and better the more you do okay how do you actually start solving these problems well the first thing you need to think is every problem or function is just a way of transforming inputs to outputs so in this problem for example we're converting a name which is a single string into a new string which is just initial dot initial so if it was my name it would go into the function and then come out like a dot j fundamentally we're just transforming this input into this output and inside our function we're just gonna have a sequence of steps each of which gets us one step closer okay so we know we need the initials get initials from name but we want to break this down into smaller and smaller steps and ideally each step would be a single line of code so what is the first thing we could do to get these initials well we could get each name or rather each word in the string first name last name separated because we need the first from each one so that would be a really good first step so maybe we want to separate first from last then once we have that we want to do two different things we get the first initial and we get the last initial get first initial or maybe it's better to write get the first character of first and get the first character of last okay now we have our two main building blocks so we probably want to combine these back together so combine with period in the middle combine with period and then that's pretty much it so we can just return this now once we have our steps here we have one two three four five and we actually also call these steps pseudocode because they are not exactly code but they're gonna roughly map to our lines of code like hopefully one for each line right but it could be more than that just to do little things like creating new variables and separating them apart so um what we're then gonna do is actually just keep this plan and we will then put our code next to it and try to write a line of code for each one of these steps okay now the first step might be a split function because we have a string and maybe we want to create an into an array of size two one with the first name and then one index with the last name so let's say we we know split because we saw it in a tutorial but we don't remember exactly how to do it and i hate to break it to you but guessing never works when you're coding so what you're going to want to do is something like this okay we're going to declare a new variable and we'll call it first and last and that's where our array is going to go that's returned from the split function and this is of course javascript by the way but you can do this in any language so i'm going to do name dot split and then we'll split on the empty string character because maybe we don't remember hundred percent how split works so i'm going to just uh close that line and let me just tell you a huge mistake a lot of programmers make okay they try to type a line like this and they think it's going to work so they just start the next line but that is the opposite of what you want to do you should be testing every single line even if you're 99 sure if you're not 100 sure you should be testing every line so the way you do that is by printing in javascript that's console log what you just created and what we're hoping we created was an array of size two but we're not sure so i'll type that out and then i'll go down to this test button here and when i do that i can see that whoa okay this created a really big array with each individual character which is not actually what we wanted so now we have to do what's called debugging that is trying to fix this solution and the first way we do that is by looking up the documentation because clearly array or rather string split did not work the way we expected so we're going to get really good at googling as programmers and we'll just look up the string split function and the two authoritative sources are going to be this w3schools and developer mozilla so i'm just going to go to developer mozilla and it will show me a few examples like right at the top so yeah let's say i want like a full word out of a string uh so oh yeah i remember now okay we want to split at the space character that way we get each word in its own array index so i'm just going to update that and test it again and i know this seems like a lot of work for one line but we got our result we wanted now we can move on to get the first character so i'll just show you one more quicker example of that so let's say like i want just the first character so i would do uh first name character and then maybe i'm like okay first and last uh i think i remember zero you can move this console log down because we don't need it up there anymore make sure to change the thing you're logging out and then test then oh okay so we're getting the first word but not the first character so maybe i have to do another one of these and then okay finally we got the s so now we are done with this one and we can move on to this one so this is pretty much how you have to go it seems slow but you gotta trust me as long as you're making progress that should feel really good all right so let's move on and talk about what happens if you've tried all this and you're still just getting completely stuck so we're already here on the documentation page and i'm just gonna go back to string and i can actually see that uh if i make this window a bit bigger i can see all the string methods and in this home page i can see like different things i can do with strings so it could be useful to just browse through this uh and look at the method names and think okay is there anything that could help me here that like seems like what i'm trying to do or maybe it'll just give you an idea and this can be really really really helpful so if you're like okay yeah i forget how to like split a string apart and you're just browsing through you're like okay we have split we have slice maybe i'll open both of these in new tabs and then i'll look at each one and okay this is what slice does this is what split does and you got to realize that even if this is not going to be used in your solution you're still remembering what these do so that's really actually helping you so every little thing you look up it's actually making you a better programmer don't forget that now it now inevitably even with all these these tools you will get stuck so what do you do in that case and when do you give up well what i would say is if you're completely stuck and you've given it a real try that is like looking through the docks and you just really can't come up with anything i would limit the time you're completely stuck to 10 minutes or less and what you do from there is you can actually look at the solution and it's totally fine and a lot of people will say you know don't do it but at a certain point you're not learning anymore so you have to do it so in code wars you can hit show me the solutions uh give up you lose the ability to earn honor and then it'll show you these solutions okay now when you're looking at this solution you actually want to reverse engineer the problem so let's say you have the steps written out like we did you want to think okay what part of this is separating first from last oh it's right here okay name array name split now what's getting the first character oh it's this okay yeah i forgot you could do that and then combine with periods okay it's in the same line so you can kind of start to break it down and link it to your plan okay which is exactly what you want to do create those mental links okay let's say in a different case you got your plan wrong or you just couldn't think of how to make it this is the time where you want to do that in reverse so you'll say like oh okay so what's happening here oh i see that needed to be my first step so now you can create this step that maybe you were missing before or if you didn't have any of the steps you can just create this whole plan from scratch right so fundamentally you want to create a mental link between this and this and fill in the missing pieces and that's how you're really going to learn from these solutions okay let's say you've filled in the gap now you feel pretty good that you understand the solution what do you do next well you want to actually go back to the problem itself see if i can find my way back there and you want to edit your code and you want to see if you really do remember the solution so try to write it in without looking and then if you forget just go back to the solution but really try not to copy it word for word uh try to kind of just do it from memory as much as you can now here is how you really remember it okay so let's say you typed out a working solution instead of submitting it just hit test again and then once it works from the test you just want to hit reset and then just reset it and here's what you do keep this tab open on your computer then come back to it in one or two days and see if you still remember you can save your plan whether you write it out on paper or in a whiteboard app like this and just try to rebuild it from the bottom up and see if you do really remember it if you do remember it then you can finally hit attempt and submit the working answer if you don't just repeat the process go back to the solution see what part you forgot wait another two days and this is how you're really really going to learn it so i know this is a lot more work than just kind of looking at the editor trying different things testing it but trust me it's going to be worth the extra time and you're actually kind of wasting your time if you're not doing it this way trust me okay quick recap practice problems are what separates the real programmers from the perpetual video watchers you want to start doing them as soon as possible and i highly recommend code wars which is free and has some good easy problems think of every problem as just transforming inputs to outputs and each step in your line of code is doing that little by little you're going to want to break the solution down into steps and then ask how to create the code for that step if you have some blanks in your house like you don't know how to do one of the steps well then go to the docs first for that then you're going to want to test each line by writing in console logs or print statements or just testing it in the console if you're completely stuck look at the solution write it out yourself and then try it again another day to see if you remembered if you do this for enough problems you're going to be producing solutions easily i have complete confidence in you anyway hope that helps i'm aaron jack remote software developer and if that's your goal subscribe for more videos i'll see you soon
Info
Channel: Aaron Jack
Views: 191,860
Rating: undefined out of 5
Keywords: programming, web development, javascript, react, learn programming, learn to code, coding, software development, become a software developer, codewars, coding questions, coding problems, coding challenges, leetcode, how to learn to code, how to learn programming, best way to learn programming, best way to learn coding, fastest way to learn coding, programming problems, programming questions, programming challenges
Id: Dblfmk3ATeg
Channel Id: undefined
Length: 12min 28sec (748 seconds)
Published: Fri Dec 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.