I am sorry guys for the delay. I was not feeling well, so took a nap. My father woke me up and said you have to upload, people will be waiting. Sorry, I will automate the process from tomorrow 😊. Enjoy the video.
bhaiya after your ep -8 I solved that question on leetcode and in ( similar question ) section this question .. literally tired of solving by own at end 15/20 test case passed ,,,,,,,,, thanku bhaiya ❤️❤️❤️❤️ for this videoooo u are hero
i think instead of using an extra data structure like set , we can use a while loop instead of for loop and keep track of repetitive elements . def printUniquePermutation(inp,out): if len(inp) == 0: print(out,end=' ') return i=0 while i
to understand how the swap back function is able to give us the original string back can be confusing because we also have the perm(..) call in between, so we can lose count mentally, how many times we are forming swap. but we can understand it like this, inside perm we call an-original-swap then a perm, which can also perform an original swap. but when perm returns, the additional-swap will get operated. thus, jitne original-swap ho rhe hain, utne hi additional-swap.
Don't worry bhaiya, consistently roj video upload karna hi badi baat hai, always support you and salute your consistency bhiya.You r an inspiration for us.keep it up bhaiya 👍
My Approach by using a freq array and to store the unique permutations I used a set #include void helper(vector &nums, vector &ds, set &ans, vector &freq){ //base condition if (ds.size() == nums.size()){ ans.insert(ds); return; }
Very good explannation sir, but I've another approach..... what if we keep the code same and just change the base case. if(pos == arr.size()) { auto it = find(ans.begin(), ans.end(), arr); if(it == ans.end()) ans.push_back(arr);
return ; } this is also giving the right answer. but gives TLE.
because basically you are generating all the permutations here then for a single order you check if that is already present or not so you are checking for 2^n array permutations SO TLE
Python codes are not working properly. Can you check with them Or intimate your team to check the codes before posting in GitHub.it was not properly compiled for episode 6,7,8 so far. Hope you will resolve the issue
It is a better solution. We do not need set to solve it because set insert has time complexity of O(logn) due to which time complexity gets increased and it is simpler than using unordered_set. We can solve it using vector only. Below is the solution :- #include void permutation(string &str,int n,int i,vector &permut) { if(i==n-1) { permut.push_back(str); return; } else { for(int j=i;j
The solution above will not work. You can test it with the input abba. If you look at the first position, swapping swap(a,a) will work, swap(a,b) will work, and then swap(a,b) will also work. However, this should not work, because the permutations will be the same for this case and the previous case, so the condition is not rejecting this case. To get the correct solution, we have to keep track of each position and avoid the case where the same position already had the element that we will get after the swap. if(i!=j && str[i]==str[j]) { continue; } So keeping a set for each position(i) in the permutation function is the correct way to solve the problem.
Bhaiya I always gets confused between unique permutation and combination question, so please in next video please give the deep understanding of both so that we can find differences between them.
Instead of using sets can i simply check If( i! =pos and str[i] == str[pos]) continue ; That will be okay right? BTW thank you for this series. I have just started dsa and you are helping me a lot. Although this course is for placement preparation but i liked the way of your teaching from the basic.
you can also use a find method inside if condition(base condition) to check if the vector already exist in ans, if not then insert else return if(find(ans.begin(), ans.end(), v)==ans.end()){ //i.e. does not exist, reached till end ans.push_back(v); } return;
Logic: bring all the remaining elements in the array to the position and ask the recursion to perform the remaining task code: def permute(nums,pos,ans): track = [] if pos == len(nums) - 1: ans.append(nums[:]) return
for i in range(pos,len(nums)): if nums[i] in track: continue track.append(nums[i]) nums[i],nums[pos] = nums[pos],nums[i] permute(nums,pos+1,ans) nums[i],nums[pos] = nums[pos],nums[i] nums = [1,2,2] ans = [] permute(nums,0,ans) print(ans)
I am sorry guys for the delay.
I was not feeling well, so took a nap.
My father woke me up and said you have to upload, people will be waiting.
Sorry, I will automate the process from tomorrow 😊.
Enjoy the video.
No problem #frazbhaii
How are you feeling now??
No problem bhaiyya
stress mat lo ❤️
Koi nahi bhai ❤️
no issues bro, thanks for uploading 🙏
No problem bhai. Ek request the aap se bhai leetcode par karao na problems
bhaiya after your ep -8 I solved that question on leetcode and in ( similar question ) section this question .. literally tired of solving by own at end 15/20 test case passed ,,,,,,,,, thanku bhaiya ❤️❤️❤️❤️ for this videoooo u are hero
Bhai konsa q m bhi karunga
Thankyou bhaiya for sharing your knowledge for free it was great to learn from you
I am liking this series. Although I am weak in recursion, these videos are improving my thinking process. Keep it up. Good work.
Day 9 Bhai keep it up we will gonna follow till the last day of the playlist.
Thanks ☺️
i think instead of using an extra data structure like set , we can use a while loop instead of for loop and keep track of repetitive elements .
def printUniquePermutation(inp,out):
if len(inp) == 0:
print(out,end=' ')
return
i=0
while i
Great content as ever!! Learning a new way to generate all permutations by swapping instead of using a vector check.
Thanks a lot for the series sir!!
Thanks for writing bro
@@LearnYardYT Welcome sir☺️
Bro these types of manipulations in a question helps us to understand question much better ❤❤❤❤❤❤❤❤❤❤❤❤❤❤
Thanks for writing ❤️❤️
Wow, bhaiya absolutely great
Bro excellent explanation same way I thought the solving of this question after doing the previous question
So you are learning now
Thanks again bhaiya....I was eagerly waiting and checking notification for Ep-9 video🤟🤟finally and gradually I am improving myself🙋♀️😎
Thanks Shagun ♥️
get well soon bhaiya !! hats off to your consistency
Thanks for writing Yash
Thanks for the video bro...
Thanks for your time even in your tough situation
Great
Consistency ✌️✌️
Thanks for writing bro ☺️
to understand how the swap back function is able to give us the original string back can be confusing because we also have the perm(..) call in between, so we can lose count mentally, how many times we are forming swap. but we can understand it like this, inside perm we call an-original-swap then a perm, which can also perform an original swap. but when perm returns, the additional-swap will get operated. thus, jitne original-swap ho rhe hain, utne hi additional-swap.
Thank You Bhaiya for the efforts, Take care of yourself..and we were waiting but it's fine, you can take your time.
Thanks bro ☺️
wonderful explanation
Loved the lecture so much. But no more bothering comments for today. And yes a break is always necessary. Keep uploading with fresh mind ❤️. Love you
Thanks Anirudra bro
Don't worry bhaiya, consistently roj video upload karna hi badi baat hai, always support you and salute your consistency bhiya.You r an inspiration for us.keep it up bhaiya 👍
Thanks a lot for your words Isika.
My Approach by using a freq array and to store the unique permutations I used a set
#include
void helper(vector &nums, vector &ds, set &ans, vector &freq){
//base condition
if (ds.size() == nums.size()){
ans.insert(ds);
return;
}
for (int i=0 ; i
Very good explannation sir, but I've another approach..... what if we keep the code same and just change the base case.
if(pos == arr.size())
{
auto it = find(ans.begin(), ans.end(), arr);
if(it == ans.end())
ans.push_back(arr);
return ;
}
this is also giving the right answer. but gives TLE.
because basically you are generating all the permutations here then for a single order you check if that is already present or not so you are checking for 2^n array permutations SO TLE
Thanks for the lecture sir. Nice questions and content and well soon!!💖
Thanks for writing ❤️
lecture 9 Done :) ❤❤💛 waiting for next episode 👌👌👌👌👌👍👍👍💝
Coming soon bro
Bro now u r well??
#ep_9_done love u vaiya❣️❣️❤️ keep going,, we r always support u😇
Yes feeling fresh again to start recording next episode
Hi Fraz, in this lecture also we are getting the same echo in the background
i hope you have replaced your device/earphone by now, or else you'd keep writing that under every video
I tried this question yesterday.
Sorted the array which helped me to skip duplicate values.
Never thought about using sets.
Elegant Code 100%
😁 now you will never forget it
Ep-9 completed 😊🤘
Sir after doing code please dry run the code. It will give more clarity how code is working.
I tried to solve it but now i got it.
Thank you Bhaiya❣❣
You're welcome, and thanks for writing
@@LearnYardYT 🙏🙏
Python codes are not working properly.
Can you check with them
Or intimate your team to check the codes before posting in GitHub.it was not properly compiled for episode 6,7,8 so far. Hope you will resolve the issue
tanks bhaiya....waiting for new videos
Coming soon
Thanks alot bhaiya ❣️❣️
You're welcome
Ep9 also done successfully ✅
very helpful 🙏🏻🙏🏻
1st time recursion ache se smjh aa raha hai bhaiya. But aaj to bohot choti video hai. 2 question cover ho skte the
Sun ke Khushi hui
Tq soo much bro for your efforts
Thanks for writing
It is a better solution. We do not need set to solve it because set insert has time complexity of O(logn) due to which time complexity gets increased and it is simpler than using unordered_set. We can solve it using vector only. Below is the solution :-
#include
void permutation(string &str,int n,int i,vector &permut)
{
if(i==n-1)
{
permut.push_back(str);
return;
}
else
{
for(int j=i;j
We are taking unordered sets it's O(1) complexity only
The solution above will not work. You can test it with the input abba. If you look at the first position, swapping swap(a,a) will work, swap(a,b) will work, and then swap(a,b) will also work. However, this should not work, because the permutations will be the same for this case and the previous case, so the condition is not rejecting this case. To get the correct solution, we have to keep track of each position and avoid the case where the same position already had the element that we will get after the swap.
if(i!=j && str[i]==str[j])
{
continue;
}
So keeping a set for each position(i) in the permutation function is the correct way to solve the problem.
@@bishnoiankita729 I ran the program in the codestudio for all test cases it passed.
nicely explain 🙌
Thanks ☺️
DSA series is 🔥🔥
Another approach Bhaiya
#include
void perm(vector &ans, vector &arr, int pos)
{
if(pos == arr.size())
{
ans.push_back(arr);
return ;
}
for(int i=0; i
why the iteration is starting from 0??. i=pos...should be there right
Awesome content bhai 👏
Thanks
sir you are the best
Thanks ☺️
Bhaiya I always gets confused between unique permutation and combination question, so please in next video please give the deep understanding of both so that we can find differences between them.
I was waiting but not a problem
Take care
Thanks ☺️
Instead of using sets can i simply check
If( i! =pos and str[i] == str[pos])
continue ;
That will be okay right?
BTW thank you for this series. I have just started dsa and you are helping me a lot.
Although this course is for placement preparation but i liked the way of your teaching from the basic.
#ep_9 done ✅✅
We are with you bhaiya
Keep making 🔥🔥
Thanks bro 😊
Take care of your health brother
May Allah Cure you
Ameen
And Also thanks to your father for caring about us❤❤❤
Thanks ☺️
Done understood ❤️✅
Good job bro
#day 9 great explaination as always
Great
Good Video
nice explain sir.
Thanks ☺️
Done 🔥Thankyou
You're welcome ❤️❤️
Get well soon bhaiya...
Thanks ☺️
day 9 done
❤️🙌
Well explained 🤗🤗
Thanks ☺️
@@LearnYardYT 🤩😍😍
fav poet- Amhed Fraz
fav teacher- Mohd Fraz
Shukriya ♥️
Day 9 💯💯
♥️
Done!! Thank you
You're welcome
SC should be O(n^2) as we are using new unordered_set in every rec call?
you can also use a find method inside if condition(base condition) to check if the vector already exist in ans, if not then insert else return
if(find(ans.begin(), ans.end(), v)==ans.end()){ //i.e. does not exist, reached till end
ans.push_back(v);
}
return;
#Day_9
Consistency_OP 🔥🔥🔥
Yess 🔥
Please make video on how to code in geeks for geeks platform for bigenner
Present ! ✔🙌
Marked 😁
Thanks sir
You're welcome ♥️
Logic:
bring all the remaining elements in the array to the position and ask the recursion to perform the remaining task
code:
def permute(nums,pos,ans):
track = []
if pos == len(nums) - 1:
ans.append(nums[:])
return
for i in range(pos,len(nums)):
if nums[i] in track:
continue
track.append(nums[i])
nums[i],nums[pos] = nums[pos],nums[i]
permute(nums,pos+1,ans)
nums[i],nums[pos] = nums[pos],nums[i]
nums = [1,2,2]
ans = []
permute(nums,0,ans)
print(ans)
Can we get java equivalent code for the actual problem?
completed👍
Ya done completed bhaiya
Nice work
Watched episode 9!
🔥
L-9 done
Team can anyone send me java code for this practise problem
aaj 1 hr late post kyu hua , i was waiting
Sorry bro
@@LearnYardYT no worries, u were not feeling well , there is no problem
Lecture 9 Completed ☑
#dsabyfaraz💯
#recursion❤
Amazing 🔥
Concepts are clear but when it comes to solve the problem by own 🥲
bhaiya i want to ask that are these codes fully optimized?
Yes
Why this code is not working??
#include
#include
using namespace std;
class Solution {
public:
void permu(vector &arr, vector &ans, int idx, int n) {
if (idx == n) {
ans.push_back(arr);
return;
}
for (int i = idx; i < n; i++) {
if (i != idx && arr[i] == arr[i - 1]) continue; // Skip duplicates
swap(arr[i], arr[idx]);
permu(arr, ans, idx + 1, n);
swap(arr[i], arr[idx]);
}
}
vector uniquePerms(vector &arr, int n) {
vector ans;
sort(arr.begin(), arr.end());
permu(arr, ans, 0, n);
return ans;
}
};
Done✅
Great
bhaiya i got some error so where can i send u message picture
Present #frazbhaii (EP9)
Marked 😁
everything is great but dry run part is missing
fraz bhai long format videos dalo plz 8-10 minute ki videos dekhne mei mja nhi aata
Long bhi ho jaengi videos aage
class Solution {
public:
void permuteUniqueUtil(int idx, vector &ans, int n, vector &nums){
if(idx >= n){
ans.push_back(nums);
return;
}
for(int i=idx; i
Bhaiya geeks for geeks me code kar ne se phele Jo code likhe hua hote hai use kaise samjhe
Episode-9 done
First comment😊
Thanks ☺️
Please post 1hr+ video otherwise the course will take 7-8 months to compplete
Length will increase in future lectures.
Consistency ++
🔥
Bhaiya I m in 1st year ,and I am watching it but I couldn't able to understand from power set problems...
sir, your voice was echoing a bit
Will improve it