9. String Permutations Code using Recursion & Backtracking! Simple Explanation 💪🚀🔥

preview_player
Показать описание
You can practise the question here-

Subscribe and hit the notification icon to get notifications and learn with me everyday!! ❤️❤️

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

We are back! Let's practise daily? Who all gonna show up? ❤️

codefromscratch-keertipurswani
Автор

from weird Hii guys to exceptional content, hats off to you ma'am.

ayushgarg
Автор

I m so happy, after watching this ..seriously mam, you cant even imagine how eagerly i was waiting for this video, fab ❤️

purvirawat
Автор

Present.
Paused the vedio at 5:36. Thanks to the clarity in the explanation, i could code the solution in java. Passed GFG test cases.

public class FindAllPermutationsOfAString {

public static void main(String[] args){
FindAllPermutationsOfAString findAllPermutationsOfAString = new

List<String> allPermutationsResults =


}

public List<String> find_permutation(String S) {
// Code here
Set<String> allPermutationsResultsSet = new HashSet<String>();
findPermutationsRecursive(S.toCharArray(),
0,
S.length()-1,
allPermutationsResultsSet);
List<String> allPermutationsResults = new convert to list
for lexographic sorting
return allPermutationsResults;
}

private void charArray, int currIdxTargetToBeSwapped,
int endIdx, Set<String> allPermutationsResultsSet){


// we found one permutation.
// So add to the result lis
String(charArray));
}
// starting from index currIdxTargetToBeSwapped,
// swap each value with the element at currIdxTargetToBeSwapped
for(int index = currIdxTargetToBeSwapped; index<=endIdx; index++){
//swap the element at 'index' and the value at 'currIdxTargetToBeSwapped'
swap(charArray, currIdxTargetToBeSwapped, index);
// now start a recursion branch with new char array
findPermutationsRecursive(charArray,
currIdxTargetToBeSwapped+1,
endIdx,
allPermutationsResultsSet);
// now swap back the element at 'currIdxTargetToBeSwapped' and the value at 'index'
swap(charArray, currIdxTargetToBeSwapped, index);
}

}

private void swap(char[] charArray, int currIdxTargetToBeSwapped, int index){
char tmpCharAtcurrIdx =
charArray[index];
charArray[index] = tmpCharAtcurrIdx;
}
}

arunkumarmohandas
Автор

Present Ma'am. You have an amazing consistency. I was able to do this question on my own

keshavgambhir
Автор

Maja Aa gaya didi Thank you so much....

ankushladani
Автор

To be honest I was aware of the approach for this question as I had read one article earlier. So solved the question easily.

unknowncoder
Автор

Thank you soo much for going through these problems ! Done all of the problems you went through till now

phalgunibumhyavarapu
Автор

As per the concept string is call by value and every function call gets the copy of string then why it is needed to swap it back again?

Below mention code is working fine without swap it back again.

class Solution{
public:
void helper(string input, int idx, vector<string>& ans)
{
if(idx == input.size())
{
ans.push_back(input);
return;
}
for(int j=idx;j<input.size();j++)
{
swap(input[idx], input[j]);
helper(input, idx+1, ans);

}
}

vector<string> permutation(string S)
{
vector<string> ans;
helper(S, 0, ans);
sort(ans.begin(), ans.end());
return ans;
}
};

MdRizwan-uudv
Автор

I'm not just practicing but maintaining a notebook too, this is super helpful to stay consistent! Thankyou so much ❤️

parth
Автор

Thank you for the explanation. I am able to find recursion relation from the given problem but stuck with base condition always. please suggest to improve.

prakashbtw
Автор

I can't describe how falwlessly you explain your ideas. Thank you so much for all the hard works you've been doing for us.
I have a question in this video,
What is the use of swap(s[i], s[ind]); in line number 19 in the video? It gave me the same results even after commenting it. Is there anything I am not following?
Thank you in advance.

skharel
Автор

I always wait for the video whole day...

vineettiwari
Автор

Hello Mam, in next week I've an interview with Airtel of System Design round. Can you please suggest me some resources of learning System Design for beginners, I've watched your LLD playlist. I'm worries about the HLD, didn't have much knowledge on that.

surojitsantra
Автор

Where do I need to show up sorry new to the channel

jennifersweet
Автор

Plz dynamic programming Start kar dooo

imvivekkushwaha
Автор

Hi Keerthi, at 15:31 did you mean, i = 1 and index = 0?

phalgunibumhyavarapu
Автор

This is maths 11th class chapet soul this nic way ...didi

devilnk
Автор

Present....watched few videos of recursion on weekend..so no comment on that😅

shashwatraghuwanshi
Автор

Hlo mam I thing u have mistyped String as Strong in the title.

sandeepdeepu