Hi Stephen, if "3.left" is None=0 from the right side of the tree then how can you put left= 3 in the final return statement surely it should be 0 because the last value for the varaible for "left" is 0 not 3 surely?
Hi how is this linked to a stack ? Is stack only used for visualisation ? TIA The pseudo code seems much more straightforward. dfs(n, visited): print(n.value) for a in n.adjNodes { if !visited.contains(a) { dfs(n, visited) } }
I was confused about why the second while-loop only dealt with the elements in the left sub-array and not the elements in the right sub-array. The way I understand it is: - The second while-loop is needed in case "helper position-j" reached the end of the right sub-array in the first while-loop. - Another while-loop is not needed if "helper position-i" reached the end of the left sub-array in the first while-loop because: 1. The right sub-array's remaining elements are guaranteed to be of higher value than the elements in the sorted portion of "numbers-array". 2. Each of the two sub-arrays is by itself already sorted. - This means that the right sub-array's remaining elements are all of higher value AND already sorted. - The remaining elements in "numbers-array" are the same as in "helper-array" since that is just a copy, so we are done. Maybe it's just me that got confused about that but there you go. I think that's how it works...
I've been watching more than 10 videos to understand how binary tree traversal and recursion work. This is the first video I truly understand both concepts! Thanks!
this video helped me immensely, i was getting incredibly frustrated on learning dynamic programming because it looked really complicated. this video is simple and thats just what i need to understand! thank you
Ok so instead of the recursive state of a stack frame representing a sub problem we use an array. This is clearly more flexible than recursion because it's trivial for the computation of a sate to reference arbitrary other states without those values having to be threaded through function arguments and returns.
If you are searching/liking this video means you came here for recursion and not for merge sort. As you already understood the algorithm but bit confused about how recursion calling happening.
3:40 - "The amount 2 is greater than 1, so we move on" - this sounds like you're saying it should be skipped, but you go on to use it. I don't think "move on" is the right phrasing for this part of the video (if the goal is to provide a clear and easy / unambiguous explanation of the problem).
i know this is rather old video but was most helpful after digging around for ages to find a straight forward explanation of the dynamic programming solution to this problem. Thanks Steve
This is a useless video, like I understood everything and you explained it clearly, but the video is basically saying here's a solution and this is why it works. How did we come up with that solution and what was the thought process? you're on your own. This is basically a video for someone who's trying to memorize as much leetcode problems as they can to prepare for an interview or whatever, not for someone trying to learn
Hey, can someone help me at 5:30, i wondering if the recursive mergesort divides until low<high, then how is it that have merging the first two individual elements, it will mergesort and then merge. ?
Memorization is not the same as understanding, I came here to understand the problem, and this explanation falls short from that, I was not looking for a formula but for an approach that will work with other similar problems, though the video gives you the generic formula it doesn't explain its origin. one intuitive way to go about the formula is as follows: for our base case where amount = 0 and any number of coins, we only have one combination: no coins also, for any amount>0 and no coin, there are zero combinations say we have one coin [2], and one amount = 10 we can see that before we reach 10, we will reach 8 (10-2) and then 6 (8-2), and so on until we reach 0 (2-2) our table would look like this for amount 10 and coin [2] amount| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ------------------------------------------------------------------ coin=0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------------------------------------------------------------ coin=2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | ------------------------------------------------------------------ which makes sense, there's one way to do 10 with type 2 coins: 2+2+2+2+2 now say we add one more coin type (3) and our coin array becomes [2,3] we can reuse the existing table to compute the new number of combinations, we just add whatever was in that slot in the previous table so table[amount] = table[amout] + table[amount - coin] and we only care for when amount - coin >= 0 amount| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ------------------------------------------------------------------ coin=0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------------------------------------------------------------ coin=2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | ------------------------------------------------------------------ coin=3 | 1 | 0 | 1 | 1 | 1 | 1 | 2 | 1 | 2 | 2 | 2 | ------------------------------------------------------------------ we can add another coin (4), our new coin array becomes [2,3,4] amount| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ------------------------------------------------------------------ coin=0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ------------------------------------------------------------------ coin=2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | ------------------------------------------------------------------ coin=3 | 1 | 0 | 1 | 1 | 1 | 1 | 2 | 1 | 2 | 2 | 2 | ------------------------------------------------------------------ coin=4 | 1 | 0 | 1 | 1 | 2 | 1 | 3 | 2 | 4 | 3 | 5 | ------------------------------------------------------------------ So the total number of combinations to get 10 from coin [2,3,4] is 5 they are, 2+2+2+2+2, 2+3+2+3, 2+4+2+2, 2+4+4, 3+4+3, Here is the JavaScript solution: var change = function(amount, coins) { const table = new Array(amount+1).fill(0); // no coin is a combination // to get amount = 0 table[0] = 1; for (let coin of coins) { for (let i=0; i< table.length; i++) { if (i >= coin) { table[i] += table[i - coin]; } } } return table[amount]; };