Easy Google Coding Interview With Ben Awad

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everybody how's it going in this video i paired up with my friend ben a wod he's another software engineering youtuber he's got a pretty big channel in the software engineering space on youtube does a lot of unique and funny videos related to software engineering he usually focuses on front-end development so if you're interested in that do check him out but the funny thing about ben is that he is definitely not a fan of algorithm style interviews in fact he's made videos in the past criticizing algorithm style interviews but so today i decided for fun to test him by giving him an algorithm-style coding interview now in the context of google coding interviews for example i gave him a slightly easier question than the norm but i wanted to see how he would do with such a question and if you all enjoy this video a lot then we might do a part two where i give him a more difficult google coding interview question now we did this coding interview on the recently launched mock interview feature on algoexpert where you can do real coding interviews with a real other human being on a shared editor right there on algo expert by the way if you're preparing for your coding interviews or your systems design interviews then do check out my company i'll go expert go to algo expert dot io and use a promo code clem clem for discount on the platform and otherwise we also did a second video on ben's channel where he interviewed me put me to the test specifically with regards to front-end engineering so if you're interested in seeing my front-end engineering skills being interviewed or put to the test then go check out his video after you finish watching this one i'll put the link to it in the description below and in the comments below with that enjoy seeing ben put his coding interview skills to the test so ben you have seen some algo expert video ads on youtube have you not once or twice once or twice okay so do you know do you remember what one of the assumptions that algo girl makes in one of the ads specifically the one that tells you like whether or not you're a systems expert it starts by saying so you know how to do x so you know how to reverse a linked list i didn't know we were starting with jeopardy do i know how to invert a binary tree no inverting a binary tree is the scariest thing in the world or rather not knowing how to do that in a coding interview but here i'm talking about reversing linked lists if you know how to reverse linked lists then you're ready to move on to more difficult things but here the question is do you ben awod know how to reverse a linked list well i guess we're about to find out right i guess we're about to find out so that's the first part of this interview we'll call it an interview even though typically in an interview you wouldn't be specifically asked to reverse a linked list but here that's we're gonna what we're gonna do to see if bene wad can do that wait why would they ask me this in an interview why you were preparing me for interviews well usually reversing a linked list something that you need to know for interviews but it usually won't be a standalone question it might be part of another question or it might be um you know like you you might need a variation of reversing a linked list for a question but just reversing a linked list is usually a little bit too easy for an interview question all right guys i'm here all right i see ben then i can turn on i can turn on vim mode right that's the thing you have here yes so if you go do oh thank goodness if you go to sublime them you can you can turn it on oh and i guess let's change the language are you going to be writing in in typescript no no no let's do python let's do python python okay all right so then listen the prompt of the question is basically reverse a linked list so you're going to be given a linked list a linked list here you're going to get in the head of the linked list specifically and the linked list is going to have um hi youtube the linked list is going to have uh basically linked list nodes right and each node is gonna have an integer value as well as a next pointer that points to the next node in fact i can actually give you the uh struct for what this looks like give me one second so this is what your linked list is going to look like this is the type of the head that you're given and you have to reverse it and i can tell you right off the bat that doing head dot reverse is not going to work that's a bummer so you're gonna give me hints and stuff or am i just on my own here is this this is how do they do at google well so the question is do you need hints or do you need to ask me questions like are you do you have all the information that you need right now to reverse this length list so do i get bonus points if i do it all by myself maybe so if i gonna get a score at the end of this and you could tell me whether i made it into google or not if you want yes all right i'll tell you if you're ready if you're ready to interview in google all right this is this is exciting all right well we're about to we're about to find out well we're gonna say wall true here so we're gonna loop through the list and we're gonna get the next element head dot next this is gonna be my next guy and basically what i want to do and we also need to keep track of the current right so maybe we do something like that all right so i need to like this is my my next guy so okay let me give you a visual this is what i'm thinking about right now so we got a then we got b and he's touching c right and so i need to turn that into okay if i'm reversing the list you want this right yes and it should be mutating the actual list that you were given so you should not be don't let me make any ones yeah oh you know mutation is not cool bro likes immutable data types i agree i agree mutation is not cool it's the source of a lot of bugs but sometimes you do have to mutate data this is one of those times i don't know that's pretty sus but okay so c's got a point at a and b's got a point at a so let me know she's gonna point to b yeah let me let's make this a d d would be here so c is gonna be pointing backwards and this one's got a point all the way here okay i i think i knew i was doing when i started but i don't know how i'm gonna handle this last d guy we'll have to see him and just to to clarify the the last d node points to none in python and here the last a node big d alright so we're gonna say our next guy here and so we're gonna say current dot next actually we're going to say next guy dot next is equal to the current node so that would give b is now pointing at a which is what we want and then we need to go on to the next one and do the next thing so that would then go here so all right so we go i'm currently a right cur is a and i'm telling it i want it next so next guy is b and so i need to stick also i need to keep track of what b was pointing at so i can't just say next guy dot next so we'll say next next guy okay and that's next guys next before we you know wipe it out and so then we set like current is equal to do i want to set current equal to maybe next next guy actually why don't i keep track of two notes that's what i'll do like a previous or some garbage some garbage why is the previous oh this is what it this is 100 what i do actually because then that's how i set it to none so definitely this is actually definitely how it works so current is this so i know at the end current.next is equal to previous all right this is the only thing i know right now oh you guys don't have the thing you guys need the thing where i like uh command slash and comments them all out we'll do with the manual oh here we go we have that keybind in sublime but i don't think that's a them keybind is it i hear we no i have to do block mode but it's all good all right this is all i know that's right this is this is so far guys what i've concluded is right this part is a little sketchy we're going to figure this part out so curd.next is equal to previous this is what i know i think is right now maybe we just need to set like a temp previous or something so this is going to set that and maybe just like attempt previous because because what's going to happen is we need to know that this is the next node that we're doing so this is going to be like temp previous is equal to curve.next and then we wipe it out by assigning it and then we need to move on to this node so that we've correctly so if we go here okay this this part is going to correctly set this part a points at b so no it's not it's gonna point a at a that's good and this is the next one and b we just now need to point at b points at a so we really just need to set a to the previous now so here i need to set previous [Music] is equal to actually the current wait is this literally all this i think this might be all this i was overthinking this way too hard all right let me let me think if this is right so we're gonna set curd.next all right let's just put let's play it out let's play it out so okay we passed it feel free to feel free to watch an example yeah so curd.next is going to be b and we're setting that equal to to none okay and then we're setting previous oh we also have a we need a break statement here too so we're setting then previous equal to a and then the next iteration what's going to happen is oh we're not saying kerr though when yes occur what should kirby curve.next is equal i think kerr's actually just ooh do we need a temp next actually kerr yeah temp temp curve is equal to curd.next because we're wiping out that value and we need to know what it is i don't know how people explain this coherently i've been just saying temp curve previous next guy uh probably when they figure it out all right so we have the next because i didn't want to wipe this out because we're wiping it out here so i was like we got to keep the temp value right and we're going to tim cur and we're setting this all right i feel pretty good about this but i didn't think it through so let me think it through for a second let's do one more run through it all right so what's going to happen is all right so cur.next that's going to be b so this is going to be b all right so this i'm setting a to none and then previous is equal to ker all right what's ker right now curse a so previous is now a dude i just cannot type hashtags today all right so it's gonna be an a that's part of the google interview by the way whether or not you can type with hashtags yeah oh wait really no i'm joking i would see i would not be surprised if google rated like that so that's why i was like wow also going to be you know tilted towers okay so temp curse b i'm now setting current to be you know this is looking pretty good to me not gonna lie all right my base case is going to be something like i should probably think about what happens the next iteration but let me add my base case first so we right now are looping forever so to avoid looping forever how do we know when we're done just when the curve dot next is is null i believe so if not next we're going to break out and what you want me just return from here return head or occur or whatever i mean you tell me what is the question how do you do oh wait what am i doing it should be down here i'm not sure uh wait where's the og question what do you mean i just see scratch pan on the left my solution on the right is there a thing that tells me oh i see a quick quick test so the the prompt the prompt i gave you the prompt like in a in a mock interview here you don't have the actual written prompt but yes if you're asking what you should return you should return yeah mr prom give me the prompt the new head node okay so you want d for example here yes all right we'll see if this gives you d or not we'll think about that later all right value is that we don't care about value in this case all right we're very close i think let's let me just go through next iteration and make sure this next iteration works all right so after this iteration the next value comes in so this is iteration two so iteration two this is going to be c we don't need to do hashtags and uh cur is is b so b dot next is going to point at a that's what we want and then now we're setting previous equal to ker we know ker is b so now this is b and curve we're setting equal attempt curve temp curve we know is c so now it's saying c this is looking pretty good to me clement i don't know about you but this is looking pretty fine so let's okay let's do a run and see what happens before you before you run your code then because you're gonna be able to run it um first are you sure your indentation and all that is correct oh you're gonna get me like that doesn't give me squigglies in this thing let's see [Music] all right let's do some collapsing so that's inside of that let's break uh let's find out when we run it let's find out i'm i'm pretty happy about it but i mean i'm not happy about this naming convention how about that uh you're not gonna be able to rename it no oof we we we use a camel case and python to be consistent with the other ones not a best practice all right let's do my quick test okay you can just run code wait where's the run button it should be on your solution input box but i will say before you run then i will say i do think that you might have a bug in your code apart from potential like indentation issues 100 agree i'm ready to run and see some errors oops there is an issue self.next unexpected i do i do have an indentation area wait am i being a scrub oh down here the linkedin class should we remove this oh the linkedin class okay let's comment this out but that's what it was that's what was failing earlier oh my god that's what was failing the self.next that's what was failing oh so now we met now we messed up the main one let me get this straight so it was your thing that you pasted the entire time can we get that one can we get this video everyone it was clement the entire time oh my god it was the thing that i pasted okay so we might have to scrap all of this okay now i think we should be good boom okay good and now your code is failing because like i said i thought that you had a bug but we fixed the indentation guys i'm just so rattled after that i feel like i should get into google for free like uh that should be a free pass all right your code's output was the following id5 oh wait next no okay next was null value okay okay okay fair enough fair enough because i didn't keep track of the first guy i just gave him the last by the way i think your vim mode and uh cursor scrolling is broken too let me try refreshing and see if it fixes it alright yeah it's back yeah it's better now okay so let's just keep track of the first this is the the new head which is equal to none and why don't we just set i equal to zero do like an i plus oh you can't do i iplus plus because it's that language so i not i and we'll just say new head is equal to wait what am i talking about the new head's going to be the endnote oh wait i'm trolling i thought i supposed to keep track of a i don't need a i need d and d is the last node all right so d pointing at c d is d not going to be my current node at the very end so if curve.next well think about it look at look at the output look at what you're what you're outputting you're outputting only a single node why are you outputting only a single node that's the head okay why is your head pointing to null as the next value because i told the break to when it was the next but i need to bring at the bottom first and sign it first i suppose i actually thought about this earlier i was like i don't know if my base case should be there but i forgot about it let's do like temp cur.next was that b yes but but this so if my next one's actually but actually no is that right previous not next equal previous nope i think that's right let's try it let's run it shipping oh now we just returning null if not cur oh we need to put it right here there we go hey pass the test case [Music] let's run let's run all the tests and if those pass then i'll go girl will be impressed all right i'm going to be put on all the tests just run code now 7 out of 7. look at that all right well then minus a few quirks where i'll take one for brought to you by clement i have someone who who messed those up turns out we didn't have a bug by the way in the in the indentation it was literally just because we me i miscopy pasted something that had different indentation and by the way bug and clement for the record like can we all agree that python indentation is just like the the worst thing in the history of programming only for weak-minded individuals all right so ben since we were able to do this in roughly 20 minutes and probably like 15 minutes if we remove that indentation thing why don't we do one more little challenge i'm ready this was easy piece of cake and by the way by the way have you ever reversed a linked list in your life uh probably like a really long time ago yeah okay okay but this was this was definitely on the spot like i wasn't going for memory but i i just kind of did it until we got there yeah i could tell you where you were working your way through it you were coming up with logic um which was good but so now you hinted at this at the beginning of the of the video what is the scariest thing in the world then angularjs apart from angularjs uh inverting a binary tree i guess am i averting a binary tree now you're about to invert a binary tree and i just sent you another link to join you are about to invert a binary tree button wow this is the scariest thing i've witnessed in my life guys ad rings true oh by the way i should i don't know why i want to do this i should have been full screen my code we're full screen now baby all right let's also while we're at it i mean i see that ben 10 is connected to the workspace so here you are going to be inverting a binary tree you are given a binary tree by youtube again another typo minus 10 points on your score for your google coding interview um you're going to be taking in a binary tree class every node has a value a left pointer and a right pointer and you want to invert every node in the binary tree can you draw me a picture uh yes so if you look at your scratch pad oops this is like an input tree that you might be given you would be given the root node 1 right and you would want to return something like this and you would want to return again the the root node or you could just i think you could just do it in place you don't even have to to return anything for this particular question absolutely like you can once again you have to mutate you have to mutate you can't create wait this is all inverting a binary tree is yeah wait i thought oh there's more to it i thought this was like we actually flipping on its head or something this is it well here you flip it on its body okay i'm feeling confident now i'm feeling confident you you guys need to find a different thing for the hardest you know the scariest thing i'm actually less scared once i see this i actually thought it was gonna be scary i mean you you can reverse length liz then what can't you do if you can reverse a lengthwise i guess fair enough fair enough we're about to find out i think i'm gonna be able to do this faster than my uh reverse length list i'm getting really cocky for some reason but this one just like i'm looking at it and i actually like in my brain i'm like don't we just put you know left equals right so we're about to find out i guess because it's recursion i haven't done recursion in a long time let's see if you can do it we're gonna see if it comes back to us all right so we're just going to he said tree left right so i think we just say um we're gonna we ignore we're done or we if tree dot left do i want to oh that's that's our oh we'll just stay here so i don't go to full screen there we go we'll do our ghetto full screen mode all right so that's gonna be our base case so we'll do base case or when we recurse last okay can i assume the tree is not going to be do i need to do an if trees like null or something here can i just do tree dot left or second and get me i mean you will never be given you will always be given a valid input binary tree if that's what you're asking so the the root node that you will be given will always be a valid binary node okay but then all right so that's that that's like invert binary tree by the way if it's not this easy then we're in trouble i was hoping it was going to be this easy all right um and we'll just we'll just do it like this i suppose i really hope it's this easy because if it's not this easy then we're going to be in trouble all right run ben oh do we have it you are wait did you run off you're ready yup you ran out all of them eleven test cases you're ready oh my gosh that was easy to take a google coding interview easy dude inverting a link to uh freaking luke list is harder than well yeah it's a heart it's a hard time this is a medium question and reversing a linked list is a harder question than inverting a binary tree now you know what might be fun but maybe it would be for another time i should put you through an actual google coding interview because i feel like now you got warmed up this one was too easy man you yeah i need to do some more binary tree problems like this is where it's at how about this how about this if people like this video if you enjoyed watching ben a wod struggle to reverse a linked list to type hashtags and to index his code properly play the binary tree i just slayed that tree if you enjoyed watching ben awad do all this let us know in the comments and we might film a legit google coding interview in the near future with anyone wow does that mean i get a legit job after this yeah this sounds pretty legit yeah wow all right does that come with a scion bonus too if you do well in the interviews oh let's go all right so um i think that's gonna be it for this particular video hopefully you had fun then i had fun um i had a blast especially on the inver binary tree part i actually didn't know what even how to invert binary tree before this like i actually didn't even know what the problem was i just spammed it because your ad spams it well that's that's good that means that the ad like prepared you you were so you were so traumatized about maybe finding yourself in an interview not knowing how to invert a binary tree that your brain while you were like sleeping over the past few months figured out how to invert a body you made me panic for nothing you should have told me nothing scarier than reversing a link to list that one you know had me scared for a little bit we got there and for binder you have you seen anyone invert binary tree faster than that that was pretty that was pretty fast that might be like a world where we instead let's go guys comment below if you solved inver binary tree faster than this video proof because you just saw it live now now i actually like i'm really curious i want to see you i want to put you through like a legitimate interview meaning like these are classic algorithms right these are algorithms that you want to know you want to have you want to like be able to invert a binary tree i don't know about you wanna know but you know well in here for your technical interviews okay there you go imagine a use case for reversing linked list you've got like vs code stories they point to the next most popular story but you want to like reverse them yeah it's their use cases in coming the most fake use case you've ever heard ever he had to pick of vs code stories that's this example fantastic i love it but all right with that i hope that you all enjoyed the video do check out the video that we did on ben a wod's channel actually we're about to film it now he's going to put me through a front-end react spoilers spoiler alert well we have no idea how i'm going to do i'm a washed up front end developer so we'll see um smash the like button if you enjoyed the video subscribe to the channel if you haven't already subscribe to ben's channel and i will see you oh follow me on linkedin and twitter if you enjoy short form written content follow benewon on twitter and linkedin me on instagram if you like pictures and otherwise i'll see you in the next video keep going keep the plug going i like it
Info
Channel: Clément Mihailescu
Views: 620,046
Rating: undefined out of 5
Keywords: coding interview, coding interview questions and answers, mock coding interview, technical interview with a google engineer, real coding interview, beginner coding interview questions, simple coding interview, easy coding interview, reverse linked list, google coding interview, ben awad, invert binary tree, easy google coding interview, how to reverse a linked list, how to invert a binary tree, easy coding interview questions, simple coding interview questions, algo interview
Id: vHKzIPwWQkg
Channel Id: undefined
Length: 28min 0sec (1680 seconds)
Published: Fri Nov 20 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.