Hey! I am back! Thank you so much for the support! It is truly motivating. I am coming back with more videos, for now I am shifting my focus on JavaScript, but if you want me to cover anything, let me know 😀 My new video about JavaScript Objects: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-TFQQ-H5foZs.html
This is the best backtracking video i have seen. Thank you for saving me another 24 hours of effort into learning this and saving me the rest of my hair on the head from being pulled!
Wow! Your way to present materials is slightly unusual, but man! I've just seen one of the clearest explanations of backtracking and the permutation problem. Tree visualization was super helpful. Definitely got my like. Make more content!
This is the best video to start of solving a backtracking. Now I can think of optimisations, all the solutions I saw were swapping indexes but didn't seem intuitive although it's understandable. Your video is to the point and intuitive as well. Thanks
Great explanation 🙂 "Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime" Here you explained the background knowledge behind the algorithm, and not just explaining the solution flow 🙂that's how teaching should be done Kudos 😀
Thanks, this was very helpful compared to other solutions that I had encountered. My initial thought process was to use a set and do a difference between the original set and permutation, didn't think of using a simple boolean array.
I really like your soln, very clear explanation. I didnt think of using a seperate vector to keep track of used elements either - I tried to used a set when I was implementing on my own and failed miserably haha
Seemed like you got nervous when you whipped out the code haha, I feel that. Best backtracking video I’ve watched so far. You did a great job of simplifying Back To Back SWE’s videos. Adding that backtracking recipe and using it to work through the problem was great.
Hey! The video is a great introduction to the topic, but I'm afraid you're presenting it to be more trivial than it really is, which may lead some viewers to feel they understand it when they might not. If possible, breaking down the algorithm step by step and explaining each recursive call in detail (at least until the second permutation is generated) could help. The recursive calls that produce nested loops and even more recursive calls aren't simple to keep track of in your head, especially since the "undoing" at the end of the initial for loop only happens after all those nested recursions occur and call their own removals. If you do so, keeping track of which indexes are used in your "used" array instead of the actual numbers may add complexity to the process of explaining it, thanks!
Can you please explain to me how the hell does the algorithm manages to not take the previous vector and generate another one totally different? I'm having a rough time figuring it out. If the first vector was [1, 2, 3] and then deletes every element until the vector is void (and every element of the bool vector is false again), why in the world would the algorithm pick 3 after 1, instead of 2? :(
For anyone who wants a more intuitive solution the probem, by simply picking all choices 1 by 1 and also discarding the appended characters to allow for all permutations. class Solution: def permute(self, nums: List[int]) -> List[List[int]]: res = [] visited = [False for _ in range(len(nums))] def dfs(subset): if len(subset) == len(nums): res.append(subset.copy()) return for i in range(len(nums)): if not visited[i]: #Pick the choice visited[i] = True subset.append(nums[i]) dfs(subset) #Undo the choice visited[i] = False subset.pop() dfs([]) return res
Thank a lot. It was really helpful in understanding both backtracking and permutation. Future viewers, this is O(n^n ), e.g for an array lof length 3, this logic is iteratively equivalent to int len = arr.Length; for(int i=0; i < len; i++) { for(int j=0; j < len; j++) { for(int k=0; k < len; k++) { if(i != j && j != k && i != k) { List perm = new() {arr[i], arr[j], arr[k] }; result.Add(perm); } } } }
to me it seems like the return in the first if statement is unnecessary since if the goal is reached none of the choices will be valid and the recursion will stop?