Pramp Mock Technical Interview - Data Structures and Algorithms

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up guys this is Nick white I detect encoding stuff on Twitch in YouTube hopefully this doesn't join in the middle of the intro but and Beyond per amp and this is a peer-to-peer platform where you get matched to the random person who's also studying for algorithm technical interviews around the world and we interview each other so I'm going to ask this person if it's okay if they are on YouTube and if they are then we're gonna keep going with this if not okay so basically what I'm doing right now is I'm trying to do these interviews and put them on YouTube would it be okay if I put this one on YouTube or now okay all right cool don't worry I'm not like I don't have that many people I just want to like put a bunch of them on so just so people are aware of this alright so it looks like I'm going first okay cool okay I'm just gonna read it really quick and see where you know okay so sales bath the car man the car manufacturer Honda holds their distribution system in the form of a tree not necessarily binary tree the roof of the company itself every node of the tree represents a car distributor that receives cars from the parent nodes and shifts them to its children nodes the leaf nodes are car dealerships that sell cars directly to consumers in addition every node holds an integer that is the cost of shipping a car to it take for example the tree below zero five three six a path from Honda's factory to a car dealership which is a path from the root to the leaf in the tree is called the sales okay the cost of the sales path is that the sum of the cost for every node in the path for example in the tree above zero three zero ten is thirteen because zero plus three plus zero plus 10030 ten okay Honda wishes to find the minimal sales path cost in the distribution tree give it a root node write a function get cheapest node that calculates the minimal sales path cost in the tree implement your function in the most efficient manner and analyze time and space complexities for example given the Runet okay so the minimal and this one is going to be seven and it looks like there's two that give you seven seven zero six one and zero three two one okay the minimal sales path hmm okay so if we're starting at the root I think to get the minimal if we go in the direction of the smallest node that's going that's not going to work because we don't know how many nodes are in that path so we can't just choose the smallest one each time and we can't this is this is kind of hard okay so let's think about this breadth first we have breadth-first search and we have depth-first search and this is difficult I don't even know the minimal cost shortest it's not because it's not shortest path its weight is this is this cell related to like Dijkstra's okay okay okay so do you think that recursively doing this is like the best way to do it okay so if to know that might be the base case so okay what if we okay so do you think I should use a helper method okay let's see so in this case if node is null then okay wait no if we start it the root and then we keep recursively calling on the children and keep adding that value oh so there's no children than just returned okay okay I know we were saying okay I was trying to figure out the base case with that but yeah that's definitely right okay so if roots no dot children is equal to null then we can return roots node dot tossed okay and then otherwise we would do we could loop through the children I guess or we could do for node a child and we need children we can return get cheapest cost see this is weird though get cheapest cost of child so that will give us the cost of that child and then we need to add it to root node got cost plus this so that'll just that won't work well that's not gonna work cuz that's gonna just return every child's cost that is bad oh okay wait we could do this we can do like should we just do like a int min or int min cost and then we could do like in current cost is equal to this and then we could do with it they not think I'm onto it if current cost is less than men cost min equals current cost okay okay so we could do initialize okay there is no okay so this do you think this will work questions yeah yeah yeah 0 to 10 100,000 so it's not oh yeah obviously oh my gosh alright I'm sorry about that yeah you would set it to a maximum value that didn't even make sense okay okay so this sets the minimum each time and it keeps were cursing and then after at the end we would return in cost yes so does this look kind of like the solution plus child I'm still all right what I guess I guess I have to I guess I could print or something okay okay well I guess I have to make my own tests to the cost of each node is integer dot maximum value [Music] okay good is that like is that gonna break it or is that like what do you think I should do not big enough okay okay well we can do this yeah we can do integer dot max and value okay so is that kind of like the solution okay cool I would test it out but I don't even know how to test it out really I really don't even know how to test it out honestly you know I think I'd have to like build a tree or something so sorry I don't know okay so I if that is if you think that looks good then I'm satisfied because I think testing it out looks kind of hard I don't really know how to test that output I think it looks I think if you think it looks good that I'm happy with it okay all right all right ready to switch oh no you can do whatever you want it's fine [Music] how is that so I guess you're get are you given the input node or the root it looks like it looks like you're given an input node right Wow okay cool my dear with all their you know if it has the right to the right if he has the lunch child can find the right to mostly yes that's exactly right yes yes yeah that's exactly right yeah Oh Oh Wow okay yeah no it looks fine that's definitely right for sure so that there is um there's a few edge cases that is they don't that make this problem a little bit tricky but this is definitely this part is definitely right for finding the left most node in the right subtree this case is you get I think when you run this you'll actually see I think they actually have test cases set up so for this one yeah they have like unlike line 126 they have like they do like a test on nine or whatever and then you would want to get 11 I guess if we ran it so the only thing that wet is tricky is if you think about the case of [Music] 1414 returns 20 yes well you're on the right track with the parents for sure [Music] yeah yes yes and then to make it even a little more trickier if you think about twenty five and five those are also special cases twenty five is a special case because there is nothing bigger than it and five is the special case because nothing's falling on it whether you would avoid it so there is something that um five and twenty five also have in common all too [Music] [Music] it was that looks um that looks right this is right so far except for I think you might want to check against whether the parent is not null maybe so I guess if you look at 14 and you see that it goes all the way up to the very top 420 and then if you look at 12 well that would go to 14 okay wait I don't know I'm guess I'm bad at giving hints dang I'm pretty bad that's pretty close not actually my work maybe you could try like running it and see if it prints the right answer all right let's I think this one I said we can actually test it with the running but that looks pretty right that's definitely different than the way that I've seen other people do but I think it will work so the test has caused all the tests worked for nine so it looks right so far should we try a few others or we could try 11 let's see 11 is 12 that's that looks right we could try 14 oh yeah 14 was a big one I hope that works it looks really good let's try 25 yeah that looks great so I think you did a good job and yeah that's I mean it looks like you got the solution that was good so I yeah unless you want to like keep testing it or something like that or if you want to guess the time and space if you want to you don't have to if you don't want to if you want to try test I was doing them at the bottom at like 1:30 if you go to like line 131 or something you can write your own test that's right I think it's pretty good I mean I think we tried most of them all right well it was nice talking to you I'm Nick by the way yeah sure yeah I just I just do like a bunch of like algorithm stuff so yeah here I'll send it to you right and there it is okay so okay if I am use it or no it's fine if we if you don't want me to use it I just do like a bunch of like algorithm stuff and I'm just gonna do a bunch of these I want to do a bunch of these interviews because I don't think people really know about it and I want to like make people more aware of the that this exists because I think this site is really cool okay awesome really nice talking to you I hope you do well with your interviews okay so that was that was a per amp interview I'm gonna do a bunch of these and you know the I don't I don't know she I don't think she really wanted this to be on YouTube specifically but I mean she said yeah I don't think she hears that much but the yeah I'll do a bunch more I mean I don't have that many on I don't have any on so that was the first one so that's probably why it's kind of weird but the I mean it's fine I don't know I just I feel awkward about you know stuff it's so awkward asking that but yeah that's fine we're gonna do more of these parameters really awesome peer to peer connections with people and yeah definitely check them out cuz like you can do so many algorithm questions on you can do a million algorithm questions you know and that's what it is they give you an answer they give you a question you ask each other and it's really straightforward so that's about it thank you guys for watching I'm gonna do probably a bunch of these tomorrow cuz I think it'll be really fun to do videos like this so alright see you guys Thanks
Info
Channel: Nick White
Views: 49,572
Rating: 4.9257641 out of 5
Keywords: pramp, technical interview, interview, algorithm, algorithms, data structures, data structure, coding interview, prep, mock interview, binary search tree, tree, trees, computer science, science, whiteboarding, math, computers, technology, tech, coding, programming, code, program
Id: n3fZ04zL0T4
Channel Id: undefined
Length: 40min 29sec (2429 seconds)
Published: Mon Apr 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.