Literally confusion of some questions using for loop and some without for loop is removed. Every yt teacher just use it randomly and explain that solution Thanku so much so helpful.🙏🙏
Java Solution for the explanation - class Solution { List result = new ArrayList(); public void backtrack(List temp ,int[] nums){ int n = nums.length; if(temp.size()==n){ result.add(new ArrayList(temp)); return; } for(int i=0;i
Even after solve a problem see your video to get in depth intuition for solve one problem and every time I able learn new thing bhaia thanks for your effort bhaia.
thanks for the explanation. i also tried without solving the for-loop but reached the same conclusion and your video clarified that. i was able to solve this myself. i was wondering how can we handle the duplicates(like in permutations II).
@@codestorywithMIK my first approach was removing duplicates from the input array i.e [1,1,2] => [1,2] but this did not work 😂 so i tried the following approach which works buts its not considered good because we are changing i at two different places var permuteUnique = function (nums) { const results = []; nums.sort((a, b) => a - b); const solve = (temp, used) => { if (temp.length == nums.length) { results.push(temp.slice()); return; } for (let i = 0; i < nums.length; i++) { if (used[i]) { continue; } temp.push(nums[i]); used[i] = true; solve(temp, used); temp.pop(); used[i] = false; while (i < nums.length - 1 && nums[i] == nums[i + 1]) i++; } }; solve([], new Array(nums.length).fill(false)); return results; };
Yesterday you gave this as an homework I solved it yesterday only....today I solved permutations ll .......your videos are literally awesome man...your teaching skills are bestest so far best jitne bhi dsa gurus bethe hai ......all the best bro...ps we are connected on LinkedIn 😆😆
You are the best! I hope you will cover everything from easy to hard on this channel. I did this question earlier as it is very popular, submitted again to maintain a streak. Now I was going to sleep but was missing your video, so I came here to see the solution of the question I already know because I was feeling your way is unique and will definitely learn something new from this, and guess what? I was right.
After Watching Your videos now i am getting confidence and I first tried to solve by myself and I stuck because their I was not using for loop , your video give me guidance on why I need to use for loop here, Thanks a Lot I am gaining my confidence, ❤ , Just One suggestion can you please start solving medium and hard Level POTD of GFG ,Please it will be very helpful that we will be able to learn 2 problem in a day in very deep manner , also 2 concepts someday.
why use set() when the result list temp itself has contains() method : set() can find in O(1) vs list can find in O(n) time. But using set creates O(n) extra space. "Space-Time tradeoff " but since problem statement specifies that 1
Super explanation bhai! Bro can we have chapter-wise break up in the video, so that we could jump back and forth into a particular section easily like : Chapter 1 : Problem intro Chapter 2 : Intuition and explanation Chapter 3 : Dry run Chapter 4 : Code Chapter 5 : Time complexity explanation.
@everyone im giving you the link of code help love babbar solution for this question match the content this person has solved the doubts that can come and babbar just gave the solution you decide you want to learn and grow or just learn no hates and offense just my p.o.v
Method 1:simple swapping class Solution: def permute(self, nums: List[int]) -> List[List[int]]: def helper(index,nums,l,ans): if index==len(nums): ans.append(nums[:]) start=index for j in range(start,len(nums)): nums[j],nums[index]=nums[index],nums[j] helper(index+1,nums,l,ans) nums[index],nums[j]=nums[j],nums[index] l=[] ans=[] helper(0,nums,l,ans) return ans Method 2:using for loop class Solution: def permute(self, nums: List[int]) -> List[List[int]]: def helper(nums,l,ans,map): if len(l)==len(nums): ans.append(l[:]) for j in range(len(nums)): if j not in map: map.add(j) l.append(nums[j]) helper(nums,l,ans,map) l.pop() map.remove(j) l=[] ans=[] map=set() helper(nums,l,ans,map) return ans
I just made up a story in my mind for the question 47 like accha here i have to do like pura toh dekho, but repeated hai numbers toh na kyu na ek frequency counter lekar chaloon class Solution: def permuteUnique(self, nums: List[int]) -> List[List[int]]:
res = set() n = len(nums) hm = Counter(nums) de = defaultdict(int) def bt(cur,de) : if len(cur) == n : res.add(tuple(cur[:]))
for i in range(n) : if de[nums[i]] < hm[nums[i]]: de[nums[i]] += 1 cur.append(nums[i]) bt(cur,de) de[nums[i]] -= 1 cur.pop()
sir muze backtrack ki ek bat samjhi nahi me recursion to samjh gaya backtrack bhi samjh gaya par backtrack use kyu kiya vo nahi samajha hu ise only recursion and dp se solve kar sakte the kya
Please first get a good grasp on Recursion Concepts. It will definitely help. th-cam.com/play/PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM.html&si=_3NfOjvBJJbSF9GU
I tried doing the same thing (passing the set itself, instead of the vector and keeping set separate). This will not work because "unordered_set", as the name suggests, doesnt maintain insertion order. You will need to use a vector as insertion order is required for finding permutations.
Thank you so much sir. I was waiting for it and your videos help alot to me. Once again, Thank you very much 🙏
Thank you 😇❤️
better than love babbar and i am not joking
🙏🙏🙏❤️❤️❤️
Damn true 🙌🏻
True bhai.
following love babbar was the biggest mistake of coding journey
I am getting addicted to this channel 💘
Means a lot to me. Thank you so much 🙏😇
Khaandani backtracking wala question ❤ ezz bro. Solve karliya fir b video dekhne aaya taki views kam na ho
It means a lot ❤️😇
Hahahah
He is the one, we all were looking for !
Literally confusion of some questions using for loop and some without for loop is removed.
Every yt teacher just use it randomly and explain that solution
Thanku so much so helpful.🙏🙏
Java Solution for the explanation -
class Solution {
List result = new ArrayList();
public void backtrack(List temp ,int[] nums){
int n = nums.length;
if(temp.size()==n){
result.add(new ArrayList(temp));
return;
}
for(int i=0;i
With each Video You are getting more and more better
Thank you so much 😇🙏
I will be forever thankful to this channel ❤
thank you so much sir from past four days i am learning from you now i feel much confident❤
Even after solve a problem see your video to get in depth intuition for solve one problem and every time I able learn new thing bhaia thanks for your effort bhaia.
Means a lot
Thank you 😇❤️
thanks for the explanation. i also tried without solving the for-loop but reached the same conclusion and your video clarified that. i was able to solve this myself. i was wondering how can we handle the duplicates(like in permutations II).
Yes thats the catch .
I will soon make video on that too.
(In short, sort the array and ensure that you don’t pick similar element twice)
@@codestorywithMIK my first approach was removing duplicates from the input array i.e [1,1,2] => [1,2] but this did not work 😂
so i tried the following approach which works buts its not considered good because we are changing i at two different places
var permuteUnique = function (nums) {
const results = [];
nums.sort((a, b) => a - b);
const solve = (temp, used) => {
if (temp.length == nums.length) {
results.push(temp.slice());
return;
}
for (let i = 0; i < nums.length; i++) {
if (used[i]) {
continue;
}
temp.push(nums[i]);
used[i] = true;
solve(temp, used);
temp.pop();
used[i] = false;
while (i < nums.length - 1 && nums[i] == nums[i + 1]) i++;
}
};
solve([], new Array(nums.length).fill(false));
return results;
};
What is the time complexity of 2nd Approach
Again , I am back doing this August challenge.Thankyou for your daily video reminder.
Let’s do it 🔥💪
Yesterday you gave this as an homework I solved it yesterday only....today I solved permutations ll .......your videos are literally awesome man...your teaching skills are bestest so far best jitne bhi dsa gurus bethe hai ......all the best bro...ps we are connected on LinkedIn 😆😆
Thank you so much
Means a lot ❤️❤️❤️
Please tell the time complexity of the second approach as well
Also, I did not understand the time complexity of the first approach. Please explain
Earned a sub my man!! Keep up the good work!
😇🙏❤️
Instead of changing approach, can we add only those subarrays whose length is equal to given array??
Bestest explanation ✨
ig the best explanation of this topic on youtube u are fire men 😇😅
thank you sir,
with the help of yours i will solve leetcode questions of August month. and i will get my 1st leetcode badge
❤️❤️❤️
Such a great explanation with so much stillness. Thank you so much sir 🥰🥰🥰
Amazing explanation❤
You are the best! I hope you will cover everything from easy to hard on this channel. I did this question earlier as it is very popular, submitted again to maintain a streak. Now I was going to sleep but was missing your video, so I came here to see the solution of the question I already know because I was feeling your way is unique and will definitely learn something new from this, and guess what? I was right.
It means a lot to me.
Thank you so much Varun 😇❤️
Great Explanation 😍
After Watching Your videos now i am getting confidence and I first tried to solve by myself and I stuck because their I was not using for loop , your video give me guidance on why I need to use for loop here, Thanks a Lot I am gaining my confidence, ❤ , Just One suggestion can you please start solving medium and hard Level POTD of GFG ,Please it will be very helpful that we will be able to learn 2 problem in a day in very deep manner , also 2 concepts someday.
Means a lot
Thank you so much
Soon i will try to cover GFG POTD as well. Just having time crunch these days due to office also
@@codestorywithMIK sure , waiting for that also ☺️
What will be the time complexity for swapping approach?
why use set() when the result list temp itself has contains() method : set() can find in O(1) vs list can find in O(n) time. But using set creates O(n) extra space. "Space-Time tradeoff "
but since problem statement specifies that 1
Thanks a lot for this.
It will definitely help others ❤️❤️
super explanation bro.really you are a great storty teller
Thank you so much 😇❤️
Really great explanation everyone can easily understand 👍 👏 keep it up. Thank you 😊
Thank you 😇
Long break Start watching again from today sir please upload daily leetcode
Sure thing 👌
Bitmask wala approach bhi samjadete bhaiya, btw loved your explanation
Sure 👌
Noted
Sir please make a video on word break, word break 2 With DP.
Sure thing
Noted
Permutations 2 ka bhi video na and discuss all possible approach pls 🙏
Sure noted
Thank you so much for this explanation ❤
You're welcome 😊
Hi Mik your intution building is great...can you please please create a playlist for recurrsion...it will be really helpful
Thank you so much.
Sure thing.
I have been planning this very soon.
However, got really occupied due to office , travel etc.
But very soon. Promise
@@codestorywithMIK Please bhaiya bana dijiye🥰🥰🥰🥰
Make videos on Subset-II and combination sum 1
Super explanation bhai! Bro can we have chapter-wise break up in the video, so that we could jump back and forth into a particular section easily like :
Chapter 1 : Problem intro
Chapter 2 : Intuition and explanation
Chapter 3 : Dry run
Chapter 4 : Code
Chapter 5 : Time complexity explanation.
Thank you so much.
I have added the time stamps / chapters. You can now access particular sections. 😇🙏
thanks a lot sir , samaj aa gaya puraa
#awesome
class Solution {
public:
vector ans;
void solve(unordered_set st,vector &nums){
if(st.size()==nums.size()){
vector temp(st.begin(),st.end());
ans.push_back(temp);
return;
}
for(int i=0;i
Can you share what error you are getting ?
@@codestorywithMIK It is giving wrong output for [6,2,-1,8]
I watch , learn and write code in java.
Mark for revision :-)
Amazing explanation ❤❤
One question , how to differentiate that this is recursion problem and backtracking problem??
Backtracking always asks for Total possibilities, combinations etc
And DP usually asks to optimise the result (minimum cost)
You are awesome 💯 mik ,I saw u started potd after a duration of long break pls continue it u are doing good for us 🙏
Yes, now I upload everyday. ♥️🙏
@everyone im giving you the link of code help love babbar solution for this question match the content this person has solved the doubts that can come and babbar just gave the solution you decide you want to learn and grow or just learn
no hates and offense just my p.o.v
Totally agree 💯
Agree 🔥
Yep correct. People will soon realise how different this channel is
Correct ✅
This is a fact. people need to see this.
This comment should be pinned.
Lol, U asked to solve it yesterday, so i did. Thus I was able to solve it from my bathroom itself (copy+paste😂)
Awesome👌🔥
Longest repeating and non-overlapping substring
DP problem,
can anyone solve this ques with recursion +memo?
Method 1:simple swapping
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
def helper(index,nums,l,ans):
if index==len(nums):
ans.append(nums[:])
start=index
for j in range(start,len(nums)):
nums[j],nums[index]=nums[index],nums[j]
helper(index+1,nums,l,ans)
nums[index],nums[j]=nums[j],nums[index]
l=[]
ans=[]
helper(0,nums,l,ans)
return ans
Method 2:using for loop
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
def helper(nums,l,ans,map):
if len(l)==len(nums):
ans.append(l[:])
for j in range(len(nums)):
if j not in map:
map.add(j)
l.append(nums[j])
helper(nums,l,ans,map)
l.pop()
map.remove(j)
l=[]
ans=[]
map=set()
helper(nums,l,ans,map)
return ans
Good morning MIk 🌅 POTD ✅
Awesome 😇👌
Solving skill is better going top thank
Indeed ❤️❤️😇
subsets question is not solving using for loop method can anyone help
Why we do undo ??? Pls explain it
Because we have to explore every possibility.
Exploring different possibilities can only be done by undoing
thanks sir
I just made up a story in my mind for the question 47
like accha here i have to do like pura toh dekho, but repeated hai numbers toh na kyu na ek frequency counter lekar chaloon
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
res = set()
n = len(nums)
hm = Counter(nums)
de = defaultdict(int)
def bt(cur,de) :
if len(cur) == n :
res.add(tuple(cur[:]))
for i in range(n) :
if de[nums[i]] < hm[nums[i]]:
de[nums[i]] += 1
cur.append(nums[i])
bt(cur,de)
de[nums[i]] -= 1
cur.pop()
bt([],de)
return res
sir muze backtrack ki ek bat samjhi nahi me recursion to samjh gaya backtrack bhi samjh gaya par backtrack use kyu kiya vo nahi samajha hu ise only recursion and dp se solve kar sakte the kya
Recursion ke andar for loop samjh nahi aata bhaiya kya karun ? :( ;
but bhaiya if i put i+1 instead of idx+1 it will be same thing?
Thanku bhaiya ❤
My man!!
thanks
Sir why did'nt we use unordered_map instead of set?
void solve(vector& nums, vector&ans, vector&op, unordered_map&mp){
if(ans.size()==nums.size()){
op.push_back(ans);
return;
}
for(int i=0; i
You can use both
done [4.7.24]✅✅
this is very hard sir...cant even understand never understand this recursion?
Please first get a good grasp on Recursion Concepts. It will definitely help.
th-cam.com/play/PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM.html&si=_3NfOjvBJJbSF9GU
❤❤
Par fir ham letter combination of phone number mein i = 0 s kyun start kiya?
Ooh got it. Kyuki hamein doosre string ko bhi poora iterate karna tha 0 s hi.
Ismein idx s start isliye kia kyuki next wale ko swap karke idx s peechey fix kar dia or ab aagey k numbers ki swapping karenge peechey walo ki nahi.
Now my question is next recursion call mein hamne i+1 s kyu nahi kia call?
Sub set2(contains duplicate)
Public listsubset with Dup(int[]nums);
listlist=new Array list ();
return list;
private void backtrack (list >list >list,list temp list,nums,int start){
list.add(newArray list (temp list);
for(int i=start; istart &&num[i]==num[i-1]) continue
templist.add[num(i)];
backtrack (list,temp list,nums,i+1);
temp list. remove (temp list ()-1)};
}
}
Array .sort(nums);
backtrack (list,new Array list(),nums,0)
🔥🔥🔥
2/30 #augustchallengewithMIK
Mentioned this hashtag in my today’s Leetcode POTD video.
Thank you so much 😇🙏🙏
WHY THIS WILL NOT WORK??
class Solution {
public:
vector ans;
void solve(unordered_set st,vector &nums){
if(st.size()==nums.size()){
vector temp(st.begin(),st.end());
ans.push_back(temp);
return;
}
for(int i=0;i
Can you share what test failed ?
I tried doing the same thing (passing the set itself, instead of the vector and keeping set separate).
This will not work because "unordered_set", as the name suggests, doesnt maintain insertion order. You will need to use a vector as insertion order is required for finding permutations.
@@DevanshAgarwal-tf7jt Thank You So much.
Sorry i missed to check after office
Thanks for covering this 😇❤️
push_back complexity is Amortized constant right ? then why we have take N ?
We are pushing an entire vector (of size N) . While pushing entire copy is made for which I have considered O(N)
bawaal explanation.
java code : "class Solution {
int n;
List res=new ArrayList();
public List permute(int[] nums) {
n=nums.length;
backtracker(0,nums);
return res;
}
public void backtracker(int index,int[] nums)
{
if(n