L12. Print all Permutations of a String/Array | Recursion | Approach - 1

preview_player
Показать описание

In case you are thinking to buy courses, please check below:

#dsa #leetcode #placements
Рекомендации по теме
Комментарии
Автор

it's very rare to find such explanations of recursion! Striver and Aditya Verma both are the best when it comes to recursion! Thanks for making recursion easy :)

arpanbanejee
Автор

ATTENTION
Are you wondering, why it is ans.add(new ArrayList<>(ds)); instead of ans.add(ds);
If you are using ans.add(ds); ds is passed as shallow copy.. the lists will be added to ans appropriately
BUT as we remove the elements from the list ds since it is a shallow copy it will also be reflected in ans list
Hope this made sense😁

samlinus
Автор

FOR THOSE, who are not getting "Why we are removing the last element after the recursive call ?". Objects like (Arrays, Maps, Custom class objects etc- all objects) in most programming languages are passed by reference in the function call unlike plain variables (int, char etc), so when you are passing the list/array to the recursive call, any updation(add/remove) on the object will be retained even after the function call finishes. Since for the right/other subtrees (of recursion call) we are not considering the same element. So we need to remove it explicitly.
If you would have passed the new replica/instance of the data structure in every recursive call, then this was not required. Hope this clears the doubt.

Manishnapstar
Автор

I came up with the exact 100% logic and code though it took me 3-4 hours but I am so happy that I did solve the problem before looking the approach or the solution all because of the previous problems of the playlist and the beautiful explanation by striver... Though, I could not think of the next approach that is swap, I could only think of the boolean approach

HarshSingh-qqjf
Автор

insted of creating int freq[nums.size()]={0} make itin vector as vector<int>map(nums.size(), 0);

vitaminprotein
Автор

Great explanation. U r the lord of Data structure and Algorithm. I sometimes wonder how you understand recursion so beautifully. This is not my cup of tea, if you are not there. Your channel is helping me a lot in understanding advance topics of DSA. I will always be thankful to you

SAURABHSINGH-xpdm
Автор

faced many difficulties when i am following another source for recursion but after learning from u now I am clear with recursion questions and also able to solve this question myself in 10 minutes thanks striver for the amazing

Code_With_Goat
Автор

very well understood, Initially i was not able to solve recursion, Dynamic programming problem.But now i am able to do that all, by just following your playlist.

SWATISINGH-imrd
Автор

Please leave a small comment if you understand by spending your time here, every comment motivates me more :)



takeUforward
Автор

The reccursion tree is really helpful thank u bhaiya🙏

_sayedramishali
Автор

Well this can be done in constant space if we just store the character which we are taking in our current permutation in temp variable and change the char by some dummy char or space and recursively call the same function while picking the char ensure that it is not a space. and while doing backtracking we can change the curr char to temp. so that our input string remains same.

salmankhader
Автор

Thank you so much brother now I'm able to solve recursions questions and also able to understand the behind of approach in recursion and backtracking
Thank you so much You are amazing man.

kirtanprajapati
Автор

Thanks, Raj you don't know how much you help college students like me. This explanation was mind-blowing.

mritunjayever
Автор

Your PlayList for recursion is the best .

scooby
Автор

I hope you are doing extremely well bhaiya ❤️❤️

prikshit
Автор

Hare Krishna! Thanks Now I can solve the Problem

SatyamKumar-bwvi
Автор

ur explanation had taken me really forward in understanding this problem as well as recursion, HATS OFF to u and ur work ♥🔥🔥🔥

nikhilpandeydigital
Автор

what if the vector nums contains duplicate elements?...this method would print duplicate permutations as well....eg if the vector contains 1, 1, 2 then the vector<vector<int>> ans would contain {1, 1, 2}, {1, 1, 2}, {1, 2, 1}, {1, 2, 1}, {2, 1, 1} and to remove duplicates without using sets?

mohitagarwal
Автор

this is the first ever videos through which i grasp my recursion concept, jiyo striver jiyo

nkgautam
Автор

thank you sir, well explained!!, and the map technique with just using an array was genius

akshayvishwakarma