wowww Nick you struggling with this question I assumed you were trying to play along or something to show how a mock interview looks like. I am just used to all your new videos :) Awesome progress. Great lessons for strugglers, keep chugging along. Love your videos :)
@OverLordOfDa3rdWorld4 жыл бұрын
wow, this is amazing! I was so afraid of what pramp would be like! Thanks for this!!
@fathimhiri59262 жыл бұрын
i just opened this video, before i fix a peer to peer interviews lol, i wanted to see how it like before
@akibislam85993 жыл бұрын
You can use DFS passing the value of current_sum to every child node. At the leaf node, you need to compare the current_sum with the global_min_sum, if (current_sum
@veipuniilana18422 жыл бұрын
static class SalesPath { int result = 0; int getCheapestCost(Node rootNode) { // your code goes here if(rootNode==null){ return 0; } helper(rootNode,0); return result; } void helper(Node rootNode,int cumResult){ cumResult = rootNode.cost; if(rootNode.children==null){ result = Math.min(result,cumResult); } for(Node child:rootNode.children){ helper(child,cumResult); } } } do you think this will work?
@barretp Жыл бұрын
@@veipuniilana1842 First line of the helper function should be cumResult = rootNode.cost + cumResult
@ok2pro3 жыл бұрын
For the first question, I solved it by gathering array of dead end nodes and while loop up to parent calculating costs until parent is nil for each of the nodes.
@laffed20454 жыл бұрын
1:04 She's so cool about it
@StockDC24 жыл бұрын
If space complexity isn't an issue, the second one can be easily solved by converting the tree into an array and then doing a linear/binary search. Once the target element is found, just return the node to the right of it. If the index is out of bounds, just return null. Not the most efficient but it works.
@Schnorzel13374 жыл бұрын
This suggestion is redicolous. You want to traverse the tree to turn it into an array (n Operations) then traverse your new array to find the solution. If you are able to turn the tree into an array you must be able to solve this problem. And there is no known data structure better for binary search than a binary search tree. Think about the name.
@vishvaschoudhary38584 жыл бұрын
More simpler approach would be to have a prev variable, do inorder search and if prev == target return current value otherwise if nothing returns return null
@淮都先生4 жыл бұрын
I guess dfs+backtracking is what the problem wants to check after first glance.
@karthikmucheli79305 жыл бұрын
The first question. I am just 5 mins in, it seems simple. Just DFS and return the min sum.
@g_4554 жыл бұрын
Can you share the code please
@StockDC24 жыл бұрын
@@g_455 I did it in Javascript but here's my solution. Please note that the initialization of the tree was done by someone else; I don't take any credit for it. I think the code is very easy to follow (no weird tricks) but if you need help, please let me know. repl.it/repls/DimFeistyRuntime
@cryptoisk1ng4 жыл бұрын
That is not the most optimal, this is just Dijkstra's algorithm which is BFS with Min Heap
@ishaansingh92124 жыл бұрын
Karthik Mucheli u should use pre cost totals instead...the node class should have a list of possible costs
@Aziqfajar4 жыл бұрын
I thought the solution would be to find minimal cost, since it says that return the minimum. So, by iterating for every node would be the solution, even if the time complexity would be n^2.
@Aziqfajar4 жыл бұрын
This interview is smoother than a butter on a toasted bread.
@hungryXD3 жыл бұрын
WOAH! THAT'S REALLY SMOOTH!!! 😲
@yechanlee70663 жыл бұрын
Isn't the first question just a variation of leetcode PathSum? Just adding a min counter will be enough.. It's an easy question in leetcode.
@some_20s_guy4 жыл бұрын
I liked the idea about how you let the interviewee to think about her approach, instead of blabbering away about the question. Seems quite annoying when you don't get the time to read the problem 😁
@nicoqueijo4 жыл бұрын
Isn't it weird that these Node classes have references to their parents? Kinda gives tree problems a new meaning...
@hatrick31174 жыл бұрын
Yeah... I don't like it, It's like you found a solution but there is this parent that you never used, and it's bothers you, like you missed some secret.
@joecamroberon93225 жыл бұрын
Please do more of these if you can!!!
@NickWhite5 жыл бұрын
just made another video will post it soon
@joecamroberon93225 жыл бұрын
Nick White sounds great. I just spent like 5 hours today watching your vids. Going to hop on hackerrank tomorrow and solve some problems. Also, thanks for the inspiration and motivation.
@yodgorbekkomilov33834 жыл бұрын
@@joecamroberon9322 good luck mate I have an interview today
@ozzyfromspace2 жыл бұрын
Yo! I was on Pramp earlier today and actually got this question 😅. What are the odds of that? Somehow the interview gods were with me and I found an efficient solution.
@@lakshminarayan1564 Yes and it is. The call is root -> child[0] -> child[0] .... -> child
@Schnorzel13374 жыл бұрын
This is not shortest paths problem. Dijkstra answers exactly this: What is the min distance from Node x to Node y of a graph. We want to answer, what is the min distance from Node x to all leaves {l1,l2,...,ln) thats closer to floyd warshall than anything. But still wrong, any tree traversial can solve this. And no, Travelig salesman cant work on a tree, because any graph that is not hamiltonian cant have a solution. And TSP is not even solvable for that many nodes.
@kushaljha54153 жыл бұрын
root to leaf problem this is very easy prob imo
@rohitkumar29844 жыл бұрын
I had to build the tree in pramp interface to test it.
@huxiaoxu4 жыл бұрын
I think the solution is that BFS with Priority Queue.
@PoulJulle-wb9iu4 жыл бұрын
PQ why ??
@MrKrazeeNinja4 жыл бұрын
@@PoulJulle-wb9iu optimise the solution to get to the shortest path first rather than test unnecessary neighbours
@dhananjayand30574 жыл бұрын
Change the LinkedIn link in your description. Check the link mate
@marcosissler8 ай бұрын
Wow, thank you guys for sharing this experience. Amazing and super useful.
@yuliu86524 жыл бұрын
For first question, you can use post order of tree, from leave to root
@ishaansingh92124 жыл бұрын
Yu Liu that’s what i was thinking, more efficient
@Schnorzel13374 жыл бұрын
Whats wrong with good old preorder? You visit every node exactly once, thats optimal without pruning allowed.
@Schnorzel13374 жыл бұрын
@@ishaansingh9212 How is that more efficient?
@rockgamerz20644 жыл бұрын
I think preorder is better.
@abhishekkadam29994 жыл бұрын
I am surprised that no one has yet commented on this, but, I think the first solution won't work.
@hawktomnia0074 жыл бұрын
he declared min_cost outside of the function as a global variable and then returns min_cost for each recursive call. It's confusing
@lekdendorji6a4 жыл бұрын
Declaringthe min cost outside the function wont workk
@g_4554 жыл бұрын
It would be great if you can share the code for the solutions as well
@calmVlogsKannadiga4 жыл бұрын
I think kurskal or djikstra's algorithms can be used and modified a bit to find an effective solution
@Schnorzel13374 жыл бұрын
(Kruskal) A Minimum Spanning Tree is not a solution to this problem, also you got a tree not the list of vertices so you would need to visit the tree just to find all vertices and then do Kruskal which would output the tree. A Minimum Spanning Tree of a tree, is the tree itself. (Dijkstra) Again wouldnt work because you dont have the vertices. And what would be the question? The minimum path from the root to every leaf? Thats not Dijkstra anyway. Thats half way to Floyd Warshall. The shown algorithm is nearly optimal (if the global variable would be inside the function) and you shouldnt reinvent the wheel. Only thing you can add is, if you got the minimum for the left tree you can stop traversing the right tree if the cost is matched or exceeded.
@amangottumukkala29294 жыл бұрын
I really appreciate your content, but your first solution is completely incorrect. It's been a while since this was uploaded so I'm sure you know how to solve it now :)
@sanskarkaazi38302 жыл бұрын
Can I get the problem link to this question?
@veipuniilana18422 жыл бұрын
static class SalesPath { int result = 0; int getCheapestCost(Node rootNode) { // your code goes here if(rootNode==null){ return 0; } helper(rootNode,0); return result; } void helper(Node rootNode,int cumResult){ cumResult = rootNode.cost; if(rootNode.children==null){ result = Math.min(result,cumResult); } for(Node child:rootNode.children){ helper(child,cumResult); } } } is this right?
@somak45224 жыл бұрын
You are a good guy nick ✌️
@hasa46282 жыл бұрын
Did u know the questions before the interview
@andrewv85484 жыл бұрын
I have no idea what she's saying half of the time
@JamesBond-bi2cr10 ай бұрын
These Chinese can't even pronounce properly
@iohin7 ай бұрын
That’s often how real interviews go
@cooldhongibaba4 жыл бұрын
I'm still confused about the first solution tho. Because of the fact that min_value is a class member and once it reaches, for example the branch 1 -> 1 it would assign the value of min_value to 2 => rootNode.cost + getCheapestCost(child ). Once it assigns that value to min_value, it wont change throughout the whole search. Any thoughts?!
@vishvaschoudhary38584 жыл бұрын
Yeah so the idea of min_value is to not compare it with the sum before we reach the leftmost child which can be done with preorder in which we'll recursively call the leftmost child and adding the node value than compare it with min_value
@bauyrzhanmaksot30225 жыл бұрын
you have to visit at least each node once, here you are traversing through children of the root node.
@Schnorzel13374 жыл бұрын
You missed the recursion. He visits every node.
@shufflingutube4 жыл бұрын
gosh algorithms are hard
@pankaj37469 ай бұрын
Nick is pretending to be a begineer, that's kind of funny! I don't solve that many leetcode questions, but the first one is so simple, even I recognized that it's a depth-first-traversal problem!
@AaronBondSU5 жыл бұрын
are you still streaming on twitch?
@NickWhite5 жыл бұрын
Aaron Bond yeah but I’m just trying to grow my KZbin right now I’ll probably go live again soon enough
@istiaque-ahmed Жыл бұрын
Why don't you upload new video please ?
@tejassardana62664 жыл бұрын
Her smile is so cute
@powerToYourself364 жыл бұрын
This is so cool 😎
@iohin7 ай бұрын
1:00 l i don’t have too many people…” 300k subscribers
@captainalpha48534 жыл бұрын
Great video!
@risingpowerАй бұрын
"i don't have a lot of people" 384k subs later... hahaha
@PoulJulle-wb9iu4 жыл бұрын
how this guy got interview at google? GG mate. she rocked it though
@MElixirDNB4 жыл бұрын
why dont you watch his 5000 videos where he solves typical interview questions dumb dumb
@MElixirDNB4 жыл бұрын
@@doublesid1395 No its not, its all about practice. The more you do it the easier it is to do, whether someone is watching or not. With practice you also get confidence so its not so nerve wracking in front of other people, plus they are usually nice and helpful
@pinkylover9112 жыл бұрын
your peer is cute :)
@JSDev7763 жыл бұрын
such acting much wow! LOL
@rohitkumar29844 жыл бұрын
I had to build the tree in pramp interface to test it.