At 6:40, the nodes are pushed in the order E,D,C,B. This would only happen if the adjacency list was written like this, A:E,D,C,B. While there is nothing technically wrong with that, they would usually be written A:B,C,D,E and thus the stack would look like this (from bottom to top) B,C,D,E and then the first node to get processed and printed after A would be E. The way he did it made the output look nicer because it was all in order, but that is not how it would normally happen, since the conventional way is to write the vertices/nodes in alphabetical order. Although yes, you can write the adjacency vertices/nodes in any order you want.
@sallaklamhayyen98763 күн бұрын
Brilliant as always = thank you so much🥰
@nan0663 күн бұрын
oh my gosh thank you.
@recoverybot7774 күн бұрын
amazingly explained
@heyjoe59205 күн бұрын
Man, thank you so much. Great explanation, especially of O(1) space solution.
@mounirzouhari64535 күн бұрын
wow this is the best explanation
@LizyAd6 күн бұрын
Perfect explanation. Thanks
@CometSpy6 күн бұрын
Thanks man :)
@ChideraAbaraonye6 күн бұрын
You're the best teacher ever, and I'm being VERY honest. You have helped me understand concepts I used to struggle with
@ChideraAbaraonye6 күн бұрын
I love you man
@aadilbutt88096 күн бұрын
WOW BRO EXPLAINED PRETTY WELL AS AN STARTER WHO WANTED VISUALIZATION I UNDERSTOOD PRETTY MUCH BRO DESERVE MORE LIKES
@ChideraAbaraonye7 күн бұрын
The best explanation i have ever gotten for this problem. I am sure i will never forget how to solve this problem again. thanks man
@kjk29737 күн бұрын
i don't comment often but i have to say nice work, your explanation was very helpful
@IshraqTanvir8 күн бұрын
hey I don't know ur name! But u just made a fan from bangladesh...Love u a lot.....ur explanation all over the youtube is just wiinning.....THank u very much..............we wanna see more
@kshitij33948 күн бұрын
Bro really loved your way of explanation. Kudos 👏
@qinyunli1528 күн бұрын
Java:class Solution { public List<Integer> distanceK(TreeNode root, TreeNode target, int k) { Map<Integer, List<Integer>> graph = new HashMap<>(); dfsBuildGraph(root, null, graph); List<Integer> res = new ArrayList<>(); Set<Integer> visited = new HashSet<>(); Queue<int[]> queue = new LinkedList<>();// int[] node and distance = new int[2]; {node.val,distance of graph from target} queue.add(new int[]{target.val, 0}); // start from target to transverse the graph : level k=0 level k=1 level k=2.... visited.add(target.val); //skip the visited point while(!queue.isEmpty()){ int[] cur = queue.poll(); int node = cur[0]; int distance = cur[1]; if(distance == k){ res.add(node); continue; } //undirected graph: node and its neighbor for(int neighbor: graph.getOrDefault(node, new ArrayList<>())){ if(!visited.contains(neighbor)){ visited.add(neighbor); queue.add(new int[]{neighbor, distance + 1});// [5,0][6,1][2,1][3,1][7,2][4,2].... } } } return res; } // Recursively build the undirected graph from the given binary tree. public void dfsBuildGraph(TreeNode cur, TreeNode parent, Map<Integer, List<Integer>> graph){ if(cur != null && parent != null){ int curVal = cur.val; int parentVal = parent.val; graph.putIfAbsent(cur.val, new ArrayList<>()); graph.putIfAbsent(parent.val, new ArrayList<>()); graph.get(cur.val).add(parent.val); graph.get(parent.val).add(cur.val); } if(cur != null && cur.left != null){ dfsBuildGraph(cur.left, cur, graph);// (5,3,graph)--> map(5,new arraylist{3}) map(3,new arraylist{5}) } // (6,5,graph)--> map(5,new arraylist{3,6}) map(3,new arraylist{5} map(6,new arraylist{5}) if(cur != null && cur.right != null){ dfsBuildGraph(cur.right, cur, graph); } } } // question :root = [3,5,1,6,2,0,8,null,null,7,4], target = 5, k = 2
@teeheeee78079 күн бұрын
Thank u so much sir❤keep doing
@kushagrakulshrestha29669 күн бұрын
CODE ➡➡ : Hello guyz, shoutout to srikant in comments for providing this random code that WORKS , not sure if it's the same as youtubers code or not, KINDLY like my comment so everyone can have code , youtuber is playing pranks with us.... enjoy and GL public Node cloneGraph(Node node) { return cloneGraphWithVisited(node, new HashMap<Integer, Node>()); } public Node cloneGraphWithVisited(Node node, Map<Integer, Node> visited) { if (node == null) return null; if (visited.containsKey(node.val)) return visited.get(node.val); Node clone = new Node(node.val, new ArrayList<Node>()); visited.put(node.val, clone); for(Node neighbor: node.neighbors) { clone.neighbors.add(cloneGraphWithVisited(neighbor, visited)); } return clone; } //ez
@darshnadrisha10 күн бұрын
How did you get an internship offer from JP Morgan?I'm Mtech 1st yr student
@cisemayaz666210 күн бұрын
what the func
@sid-oz8fw12 күн бұрын
5 years later this man is still the goat
@jitpatel110513 күн бұрын
Thank You for the best Explanation
@JogoShugh15 күн бұрын
This is freaking awesome. Thank you.
@AyazNcfli17 күн бұрын
Great!!! 👏👏👏👏
@Adam-tz6gk17 күн бұрын
Outstanding explanation thank you so much
@cozzi699518 күн бұрын
have my kids
@GeeMmm-i9h18 күн бұрын
The best explanation of this problem I've seen so far. Many other talks surprisingly don't even explain the definition of the cells in the DP table, or what is the logic behind the recursion. I wish all of the teachers and speakers were like this guy. Such a beautiful talk!!!
@junaiid010418 күн бұрын
legend😭😭😭😭🙌🏻
@junaiid010419 күн бұрын
thank you sir!
@ShikharKumar-fz6ti21 күн бұрын
Amazing video, do you have one of these Maze path for BFS, A*, Uniform Cost Search?
@tanziyang277122 күн бұрын
Awesome video :D
@tweede555522 күн бұрын
Hey man, long time subscriber here. 3 years ago I watched most videos on your channel and you are by far the greatest teacher I've had. I wish more people in the industry taught like you did - Clear and concise! You helped me crack my FAANG new grad interview, and now I'm back to get some refreshers to crack another FAANG possibly 😂. Just wanted to shout you out before I started my journey. THANK YOU! 🙏🏿
@NiaNewton23 күн бұрын
wow you made this so easy, thank you!
@AkashJha-q3r24 күн бұрын
excellent explanation
@TimonSchneider-e7b24 күн бұрын
Good one!
@sher.502725 күн бұрын
Massive respect. 🎉🎉
@21daysfromnow26 күн бұрын
I never comment but you were really helpful
@tuandino699027 күн бұрын
Im telling you im scrolling through these knapsack videos on youtube, and yours by far are the easiest to understand. I wont need to scroll anymore
@kwayfo692328 күн бұрын
very helpful!
@LizyAd29 күн бұрын
Watching from Chicago and love this so much! Thanks for clarifying this algorithm.
@ioeentrancepreparation617829 күн бұрын
@NalikaRu29 күн бұрын
really helpfull
@brianzhang8189Ай бұрын
A fun fact about the change-making problem is that we can attempt to solve it using a greedy algorithm, where we always pick the largest available denomination at each step and hope for the best. For example, suppose we have coins of denominations [1, 3, 7, 10] and we want to make 14. Using the greedy algorithm, we would choose 10, then 3, and then 1, resulting in a total of 3 coins. However, this is not optimal, as the optimal solution is to use two 7s, resulting in only 2 coins. However, there is the concept of a canonical currency system where making the greedy choice does in fact always result in an optimal solution. Nearly all modern currencies are designed this way to make it easier for the public to make change without extra mental overhead. Take US coins for example, they come in denominations of 1, 5, 10, and 25 cents. Using the greedy algorithm using this set of coins will always produce an optimal solution to the change making problem
@nuttyspasmaloid4587Ай бұрын
the clearest explanation ive seen, saved me from having to do hours of catchup xd
@All-Inclusive_CornerАй бұрын
Best teacher. I highly recommend this video .
@YouthWasterАй бұрын
Why don't we boycott universities and watch videos like this? Thanx man <3
@drikastАй бұрын
Thank you 😎
@emirhandemir3872Ай бұрын
Perfect explanation and perfect video. Everything was perfect untill I realized the fact that you didn't do average analysis until the end of the video :>(
@matthewzarate8851Ай бұрын
Seemed super long winded that I couldn't see how the smaller subproblems helped us solve future subproblems...:/