If you liked this video check out my playlist... • Leet Code top 100
Пікірлер: 105
@meamail4 жыл бұрын
This is the best recursive tree explanation I ever seen. Thank you
@Chloe-si2hq2 жыл бұрын
Thank you for your patience and hard work for actually walking us through the recursive process. The recursion tree is clear and solid. You really know what you are teaching unlike most of the LeetCode KZbinr out there who only copy and paste code. Thanks again!
@soumikkarmakar74332 жыл бұрын
No one cared to explain how recursion is working inside the for loop. But you did it thanks a lot man!!
@raunakagrawal42304 жыл бұрын
I cannot thank you more. This is actually an interview question asked by Google. You made it look like very simple with your explanation. Tons of thank you, man!
@Niceguy544444 жыл бұрын
everything is simple with good approach
@tonyz22034 жыл бұрын
You are actually explaining how to approach this problem unlike most of the leetcode youtuber( they just memorize the code and type it out). Thank you very much.
@ujjwaljha8454 жыл бұрын
This is one of the best explanation of recursion I have come across, please keep up the good work.
@danxuehuang20994 жыл бұрын
It's best ever!! Thank you so much for explaining step by step patiently lol. just hit subscribe but saw your latest update was 8 months ago, it would be great if you can keep going, your explanation is straightforward and super easy to understand, thank you!
@ansonmelakayil32813 жыл бұрын
way cleaner solution than whats on leetcode rn. good stuff man. thanks
@StyleTrick Жыл бұрын
Great solution and thinking, thanks!
@chandrashekar83094 жыл бұрын
This is it! I found the best recursion explanation. Good one 👍
@prafullakh2 жыл бұрын
Today marks 3 years since you posted this video. Why have you stopped posting new videos? You are a very good teacher, Sir. You have a divine gift. Recursive thanks to you. PLEASE START POSTING NEW VIDEOS.
@krugerbrent42702 жыл бұрын
Wow! You did a phenomenal job of explaining this in much simpler terms. Thank you so much for making this. Now, I understand this problem way better. I have one question though - Isn't the time complexity O(n * n!) from the tree diagram you illustrated? n times we are doing n! right, or can we reduce O(n * n!) to O(n!)?
@chamnil86664 жыл бұрын
This is the best recursive tree video I have seen so far.Thank you so much SIR,now I can eat something,since I got it down.I was struggling to understand it for over a day.Thanks a million.
@zidane61652 жыл бұрын
Read the way of solving it using GeeksForGeeks, AlgoExpert, Leetcode prime solution explanation, couple of youtube videos. Didn't understand it from any, but you. Thank you.
@leoc.96305 жыл бұрын
You said we didn't use extra space in the video, but I think newNums is an extra space in each call. Space complexity will O(n*k) where n is the depth of tree and k is the extra space in each call. Please clarify.
@grantg86384 жыл бұрын
This was the first explanation of the Permutations problem I've found that makes sense. Thank you.
@utkarshkandpal59604 жыл бұрын
answers.push([...set]) instead of this : answers.push(set) solves the problem.
@tharunkallati96314 жыл бұрын
Can’t agree more!!!
@aniruddhashahapurkar9244 Жыл бұрын
Best explanation!!
@Zoe-fw6kt Жыл бұрын
please start posting new videos, I watched loads of algothrim videos, yours are the ones that make more senses. and easier to understand, Thank you~~~
@joseulissescastro4883 Жыл бұрын
That was the only video that helped me to really understand what happens in a backtracking solution. Thank you sir
@admercs2 жыл бұрын
Nice explanation!
@navderm2 жыл бұрын
the removal of one element from an array itself is an O(n) complexity. That turns your solution into O(n*n*(n!))
@mistercorea2 жыл бұрын
What if you use a splice() function that will be O(1)? can you explain why it is O(n^2 * n!)?
@navderm2 жыл бұрын
@@mistercorea How does splice work internally? How do you say that splice is an O(1) algorithm? Splice itself cannot be O(1) but at the minimum has to be O(n).
@iamkarthikkeyan4 жыл бұрын
Thanks for the clear explanation. This is the best explanation.
@thajafsal4 жыл бұрын
Cracking the code interview book says the time complexity of this algorithm is not n!
@reelinvestor4 жыл бұрын
The book is right, in the video he didn't take into consideration the additional time required to copy into a new array while removing the item.
@xinhe39895 жыл бұрын
The great explanation about tree and recursion.
@sanskarkaazi38302 жыл бұрын
Can somebody do this with java. ?
@KarthikParthasarathy4 жыл бұрын
Time Complexity Infinity is a great concept , great channel and some brilliant work here
@tirthshah8550 Жыл бұрын
What is the space complexity for this
@poojakadiyan87904 жыл бұрын
very helpful recursion tree visualization
@xmaxfuture4 жыл бұрын
dude, u have the best explanation for this question
@ponssuarez45135 жыл бұрын
Keep on teaching Man!
@lamaalnajjar10038 ай бұрын
great explanation !
@slymastera4 жыл бұрын
Thank you.
@saelkhlouf1695 Жыл бұрын
Man you are a life saver !
@michaelc88764 жыл бұрын
I used Java to write this code. But I get something wrong, the result would be [1,2,3] only. What's the problem with my code here? And how to write it correctly in Java? public List permute(int[] nums) { if (nums == null || nums.length == 0) return new ArrayList(); List result = new ArrayList(); List list = new ArrayList(); for (int num: nums) list.add(num); List todo = new ArrayList(); backtrack(list, todo, result); return result; } private void backtrack(List list, List todo, List result) { if (list.size() == 0) { result.add(new ArrayList(todo)); } for (int i = 0; i < list.size(); i++) { todo.add(list.get(i)); list.remove(i); backtrack(list,todo,result); todo.remove(todo.size() - 1); } } Thanks a lot!
@akhilkandibanda4 жыл бұрын
dude amazing explanation thanks
@ShubhamKumar-sj6dp Жыл бұрын
this is the best illustration for recursion tree when called under a loop, every video just draw a two way or three way branch from beginning but this was exactly step by step , thnx
@prvizpirizaditweb23243 жыл бұрын
I am really curios about what is really going on behind the scenes , for example when for the first time Permumation returns ,the next line set.pop is executed. But what was the next step? did it return back to the previous function call in the callStack( which seems it is) or did it just increased the i in for loop?
@oziomaogbe86653 жыл бұрын
Love you bro
@roshni9623 жыл бұрын
Thanks :)
@dhillon64492 жыл бұрын
the best
@aaronargottelopez34883 жыл бұрын
Thanks
@utkarshkandpal59604 жыл бұрын
IN line 6 why are we doing this : answers.push([...set]) and why not simply this : answers.push(set)? set is an array and we can simply push the array into the answers array ?
@Paradise-kv7fn3 жыл бұрын
we don't need to create a new list every time. We can use :- def permute(self, nums: List[int]) -> List[List[int]]: n = len(nums) ans = [] def rec(path): if not len(nums): ans.append(path[:]) return for i in nums[::-1]: nums.remove(i) path.append(i) rec(path) path.pop() nums.append(i) rec([]) return ans
@prakashgatiyala9869 Жыл бұрын
😇
@whiteeye2121movalik3 жыл бұрын
is it allowed to add function parameters? not leaving just the "nums" one? I thought you are not allowed to do that....
@quochunghoang88332 жыл бұрын
Wonderful recursive explanation !!! Thank you.
@mauricegoldberg74584 жыл бұрын
Finally I get it!! thank you king
@ruixue69552 жыл бұрын
1:22 algorithm - 1:29 recursion 1:54 go through the recursion tree 2:40 11:46 code
@gurjotsinghsidhu16433 жыл бұрын
Very nice explanation. Can someone show how to do write this in Python?
@eltonstalspets454 жыл бұрын
Hi. I've tried to make sense of this for a long time but I am still confused. Because the base case (the if statement) is checked for before the nums array is filtered, shouldn't there be one more step of the tree for just pushing the array into the answers. In the tree showed in the video, the last step does not meet the base case because nums is not empty when the base case is checked (nums === [3]). Could someone please clarify?
@vibhavkushwaha58093 жыл бұрын
it was a piece of cake for you. And now for others too. Holy moly how well you explained, i cant describe it words, it was way to easy for us to understand what's going on. Thanks a ton mate. Cheers :)
@becktj3 жыл бұрын
A very good explanation. I had to watch it 5 times though lol. Thank you!
@cooldude30104 жыл бұрын
Your use of filter to remove an element at an index is awesome. I've been using splice() with concat() but filter() is so much more elegant.
@mistercorea2 жыл бұрын
splice should be faster than the filter.
@archanamasilamani51155 жыл бұрын
One of the best videos on recursion. Thanks!
@alex.perreras4 жыл бұрын
num.filter has O(N) time complexity - your final complexity is even worse than O(N!). Be careful using this at interview!
@leohippochin7082 жыл бұрын
This video is very well done. Good Job. Man!
@danishuddin97522 жыл бұрын
Thank andi guru garu, ee logic ardham kaaka oka roju antha chacchi poya!
@nutandevjoshi4 жыл бұрын
I had to play 0.75 speed. But so far its okay, will update after I complete video.
@legion_294 жыл бұрын
Please add more LeetCode challenges.. your explanations are awesome. Thank you.
@doug81713 жыл бұрын
heap’s algorithm is another way I believe.
@jameskanyi73763 жыл бұрын
Would you mind explaining how this code will work in a stack frame?
@justadev____72323 жыл бұрын
Beautiful explanation! Been looking for something like this for a while now!!!
@allenllewellynkra4 жыл бұрын
Brilliant explaination. Please do more videos
@王传玮3 жыл бұрын
nice explanation,thanks man.
@deepakranganathan96443 жыл бұрын
Best explanation thanks :)
@Respect_Mah_Authoritah_4 жыл бұрын
Why do we have to do set.pop()
@markliu223 жыл бұрын
Anyone know the space complexity? Thanks in advance!
@burntalmonds95983 жыл бұрын
I believe O(n!) as well because the array containing the answers will have that many elements
@AJewFR03 жыл бұрын
Its O(n!). The amount of permutations that you make is n!. your array then is n! large.
@sonukapoor19783 жыл бұрын
Make more videos
@jsjsjs11163 жыл бұрын
this guy is a god
@joelcruz28733 жыл бұрын
Great video!
@vtserej3 жыл бұрын
best explanation so far
@saumyaranjannayak21013 жыл бұрын
Awesome !
@apratim19194 жыл бұрын
Beautiful
@psettii4 жыл бұрын
Can any one please share code for Java ?
@jagritbhupal58364 жыл бұрын
I used general backtracking logic to implement this. I don't know if its similar to what he is implementing as I only watched the logic. class Solution { List list=new ArrayList(); public List permute(int[] nums) { backtrack(new ArrayList(),nums); return list; } public void backtrack(List curr,int[] nums) { if(curr.size()==nums.length) { list.add(new ArrayList(curr)); } for(int i=0;i
@sannge79674 жыл бұрын
@@jagritbhupal5836 hey, can you please explain the code by chance?
@kmn17943 жыл бұрын
Why poke yourself in the eyes and into the brain when learning a new concept whilst coding with Java will do it for you.
@cindy__49204 жыл бұрын
Thank you for your explanation! It is pretty useful!
@sandeshrana72253 жыл бұрын
best one
@skkkk31054 жыл бұрын
Can u please add java code?
@rakshith35474 жыл бұрын
good explanation
@0xSol_Invictus4 жыл бұрын
These things always make sense in hindsight once it's been explained, but do normal people actually come up with these crazy-ass solutions on their own?? Need to figure out what to take away from this conceptually so I actually learn something instead of just being able to do this exact problem if I see it again.
@imjeffreylee4 жыл бұрын
I guess this is how it works. Problem solving is all about reading the pattern, the more problems you solve the faster you can come up with an idea what algorithm you need to apply. You can say that we are memorizing it, but who isn't? That's why "Practice makes perfect" is a thing. I know I probably never gonna use it again when really working, unless I am on an algorithm research team, but this is how the game is played.
@allenalex48614 жыл бұрын
Exactly What I've been thinking.how on Earth do these guys come up with such solutions.😂😂😂
@senthamilsindhu9014 жыл бұрын
Great explanation. Thanks!
@TanujDhaundiyal4 жыл бұрын
Explained in such an easy manner. Thanks!
@piyushsharma16385 жыл бұрын
Very well explained video, thanks.
@anmolcoolsinha4 жыл бұрын
Can someone give the java version of this?
@tonyz22034 жыл бұрын
Yes
@tusharborole61555 жыл бұрын
you are best teacher so far
@ほっしゃん-b8b4 жыл бұрын
genius
@joshr97035 жыл бұрын
thanks m8
@MarsTheProgrammer4 жыл бұрын
you lost me 3 minutes in lol...
@Dan-tg3gs4 жыл бұрын
Good explanation but im not sure if its the best implementation in code? I've seen this problem solved using 2 functions with different # of parameters, what are the pros and cons of both implementations?