Dude you gotta manage your mic clipping the output. Great content, but hard to listen to.
@ConwellConwell Жыл бұрын
Nick helped code 911 and grinder
@milad9505 жыл бұрын
dude massively appreciate these videos!
@antonantochi84982 жыл бұрын
Classic recursive DFS here...what is stack for? When you starting to use linkedlist as a stack, always think first if you really on a correct way :)
@simonkaranja38112 жыл бұрын
Thank you my code teacher for always doing an amazing work. Look at this solution. Has a runtime of 1 ms. class Solution { List ans = new ArrayList(); public List postorder(Node root) { if(root == null) return ans; for(Node child : root.children){ postorder(child); } ans.add(root.val); return ans; } }
@sharidass14084 жыл бұрын
Good Job Nick. Helps me to wrap my head around problems quickly
@AnotherCogInTheMurderMachine Жыл бұрын
Can somebody please explain why does the "for-each" loop not throwing a Null Pointer exception when "node.children" is null ?????? For example Node with val = 5 does not have nay children, but in this code we still try to iterate through his children
@HitHard1008 Жыл бұрын
The foreach loop will not even run once as node.children.length will be zero.
@Matlaps123 Жыл бұрын
Great video! Is there any specific reason you didnt just use a normal stack, Nick?
@awesomebearaudiobooks Жыл бұрын
In Java, it's preferable to use LinkedList instead of Stack, because under the hood, Stack is implemented/inherited as a child of the Vector class, which is generally slower than using the LinkedList, which is a direct implementation of the List interface. In fact, it's recommended to never use anything that inherits from a Vector class, unless you REALLY need it. For example, Stack (or any other Vector) would be a viable option if you had a very old version of Java AND if your project requires multithreading (because in the older versions of Java, you couldn't use LinkedList in multithreaded apps, while you could use Stack). In the modern versions of Java, LinkedList is almost always preferable to Stack.
@syakov063 жыл бұрын
Why not to use recursion?
@mohammedghabyen7212 жыл бұрын
Another way to solve this in c#: public class Solution { public IList Postorder(Node root) { IList res = new List(); if(root==null) return res; if(root.children.Count==0) { res.Add(root.val); return res; } addData(root,res); return res; } private void addData(Node node,IList res){ for(int i=0;i
@Firecloak4 жыл бұрын
short and straightforward. thanks
@Turnpost25523 жыл бұрын
Name of stack was bad naming. Its a friggen linkedlist. However it behaves like a stack.
@RBNrocks11 ай бұрын
class Solution { public List postorder(Node root) { List result = new LinkedList(); process(root, result); return result; } private void process(Node root, List result) { if(root == null) { return; } for(Node child : root.children) { process(child, result); } result.add(root.val); } }
@javaluvawithjeremystones63153 жыл бұрын
Thanks for making these vids. Stack is LIFO, yours is just a backwards queue, not a stack, because it’s a FIFO implementation.
@Sandeep-tx5jh3 жыл бұрын
In array, elements by default are inserted at last and he used polllast() it implies stack itself right
@albert_schneider5545 жыл бұрын
do the tech companies allow to use c++ stl and other utility functions during tech interview???
@xavierelon4 жыл бұрын
Yes of course
@treyquattro4 жыл бұрын
yes but you should know how to implement the algorithms you use
@joycesilvera82144 жыл бұрын
don't we need Collection.reverse(node.children)??
@spandiar2 жыл бұрын
How is the "for" loop not throwing a Null Pointer exception when "node.children" is null?
@dineshkumar-kw1ik2 жыл бұрын
have you got the answer?
@hannikyaw91064 жыл бұрын
you are complicating it a lot more. we can just use a recursive approach to populate the result. it is cleaner and faster too. And a stack is not necessary.
@sarthakhejib82904 жыл бұрын
Yes, by using recursion the solution would be of 3 lines xd, but one should emphasis more on iterative approach rather than the recursive one. :)
@joycesilvera82144 жыл бұрын
but this is a follow up question asked on the recursive approach, being prepared doesn't harm!
@geoffreymak0003 жыл бұрын
I think recursion is easier to reason, but that is just me. Depends on what language you use maybe recursion is easier to code, like scala or swift.
@martianstarslit3768 Жыл бұрын
Thanks for those videos. A lot of effort put into it to make it come live. Could you speak in consideration of non-native speakers? You seem quite too fast. Thank you.😊
@knightwing78945 жыл бұрын
thanks for the walkthrough. isn't this a BFS? pre-, in-, and postorder are DFS
@NickWhite5 жыл бұрын
KnightWing yep
@NickWhite5 жыл бұрын
Sorry about that I had bfs and dfs mixed up in a few of my videos when I first started these
@knightwing78945 жыл бұрын
public List postorder(Node root) { LinkedList result = new LinkedList(); postorderDFS(root, result); return result; } public static void postorderDFS(Node head, List list) { if(head == null) return; for(Node child : head.children) { postorderDFS(child, list); } list.add(head.val); }
@treyquattro4 жыл бұрын
Yes. Also "stack" is actually a queue (but that's probably implied in the BFS-DFS mix up that Nick already copped to)
@treyquattro4 жыл бұрын
@@knightwing7894 problem description asked for iterative. That ain't iterative.
@96merluzzo4 жыл бұрын
Really spicy clap this time, well done
@jcmaybenot4 жыл бұрын
My lord and savior thank you.
@TreeLuvBurdpu2 жыл бұрын
You have like zero control over your audio volume between your different videos, I think
@pulkitgupta34774 жыл бұрын
finally high audio
@gasal.c36753 ай бұрын
ta da da da da..... keep going.. 😂 ( how loop work for bro.. )
@waeleldesoki19945 жыл бұрын
thank you :))))
@charankumar1607 Жыл бұрын
Please explain a little bit more.
@zc75043 жыл бұрын
man I pray the god to kiss you
@killingjoyandmemeing3 жыл бұрын
lol what
@vivek.tiwary4 жыл бұрын
c# implementation: No need of a linked list I guess. /* // Definition for a Node. public class Node { public int val; public IList children; public Node() {} public Node(int _val) { val = _val; } public Node(int _val, IList _children) { val = _val; children = _children; } } */ public class Solution { //uncomment for rec solution // List ouput = new List(); public IList Postorder(Node root) { return PostOrderTraversal_Iter_590(root); } public List PostOrderTraversal_Iter_590(Node root) { Stack resultStack = new Stack(); if (root == null) { return resultStack.ToList(); } var nodeStack = new Stack(); nodeStack.Push(root);//1 added while (nodeStack.Count > 0) { var currentNode = nodeStack.Pop();//FirstLoop 1 poped --//2ndLoop 4 // 3rdLoop 2 // 4th loop 6 //5th loop 5 //1-->4-->2-->3-->6-->5 //ouput.Add(currentNode.val);//First loop 1 Added to output --// 2nd loop 4 added //3rd loop 2 added // 4th loop 3 added //4th loop 6 //5th loop 5added resultStack.Push(currentNode.val); foreach(Node nd in currentNode.children) { //FirstPass for 1 enter -- //4&2 not enter, will enter for 3 // will not enter for 6 & 5 nodeStack.Push(nd);//FirstPass 3&2&4 pushed //2nd Pass 5 & 6 will be pushed } } //return ouput.Reverse().ToList(); return resultStack.ToList(); } ////Recursive soluction // public List PostOrderTraversal_Rec_590(Node root) // { // if (root == null) // { // return ouput; // } // foreach (Node node in root.children) // { // PostOrderTraversal_Rec_590(node); // } // ouput.Add(root.val); // return ouput; // } }