Minimum swaps and K together 🔥🔥| Sliding Window | Array | Brute + Optimal Approach | C++
Vložit
- čas přidán 26. 07. 2024
- Time Stamps :
Problem discussion : 0:00
Brute force approach : 02:28
Optimal approach : 04:15
Dry Run Algorithm : 05:50
Algorithm discussion : 09:31
Code explanation : 11:07
Time Complexity Discussion : 12:48
Time Complexity : O(N)
Space Complexity : O(1)
Problem Link : practice.geeksforgeeks.org/pr...
C++ Code Link : github.com/Ayu-99/Love-Babbar...
Python Code Link: github.com/Ayu-99/Love-Babbar...
Love Babbar DSA Sheet : drive.google.com/file/d/1FMdN...
Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
#DataStructuresAndAlgorithms
#LoveBabbarDSASheet
#interviewpreparation
Minimum swaps and K together solution
Minimum swaps and K together Leetcode
Minimum swaps and K together C++
Minimum swaps and K together C++ Hindi
Minimum swaps and K together Hindi
Checkout the series: 🔥🔥🔥
👉 Array: • Arrays
👉 Recursion : • Recursion
👉 Stack and Queue : • Stack And Queue
👉 Greedy : • Greedy
👉 Dynamic Programming : • Dynamic Programming
👉 Leetcode contests : • Leetcode contests
👉 Leetcode June Challenge : • Leetcode June Challenge
👉 Leetcode July Challenge : • Leetcode July Challenge
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
Great explanation! I was able to write the code myself, thanks :)
thank you for the optimized solution and all the best for your future.
Di you teach soooo well.Blessed to get notified about your channel.Thank You!!
Thank you so much Sonia. Means a lot :)
thanks for always proving for the best explanation
thanks a lot understood completely
wow! the way of explaining is superb. keep it up sister.
thank you, glad it was helpful :)
You have explained very well
thank you :)
well explained!
Waah waah kya khub samjhaya hai behen tumne....really appreciate
Thank you Riya :)
Feels like yaad karke aayi hai
very well explained!!!
Thank you, glad it was helpful :)
Great explanation
Thank you. Glad it helped :)
nice explanation mam
This question was asked in Josh Technolgy coding round but I was unable to solve it
Nice explanation
Thanks :)
Amazing Explanation Mam
thank you, glad it was helpful :)
nice explanation
Thanks mate :)
i always watch you on black tshirt di...........
Achha explain kiyaa thnx👍
Welcome. Glad it helped :). Please do share channel with your friends and juniors.
@@AyushiSharmaDSA Already shared...
@@AyushiSharmaDSA jii
didi,should we have to use j=count-1 or is it right as you mentioned above
ya i too have the same doubt
@@nvyashwin5512 same doubt
j = count, because we have already calculated for 0-count-1 initially, Now the for loop is deciding to add J and remove I, that is add the j= count element and remove i=0 element. Hope it helped
Nyc explanation
Thank you :) glad it was helpful
@@AyushiSharmaDSA maam, u explained solution in simple way i hope it will help more students to understand this question.
@@vinaymaurya3038 thank you Vinay🙂
why is ++count and not ++count and also ++i and ++j instead of i++ and j++? could you pls explain
Anyways these are written as increment statements, they work the same way. In for loops the increment statements will be executed at the end of iteration
Can I use Dutch flag algorithm
i diidnt understand the last for loop , why j=count?
As we need to group all elements less than or equal to k together, we take the count of such numbers then create a window of that size, thats why j is initilized with count.
Thanksu
Welcome 🤗
@@AyushiSharmaDSA didi how can i find subarray in (n2) array using loops?
in third FOR loop ,shouldn't we start by i=1,j=count+1.Because we have solved this window in second for loop. ALSO IT COULD CAUSE ERROR AS IN THE SAME WINDOW I=0 TO J= COUNT ,WE ARE DOING OPERATION TWICE .Please reply ,may be i M WRONG.
,FOR ex suppose we choose a window 6,7,2 .bad word =2 if k=3 in 2nd for loop .But when we come to third for loop since 6 at index=0 >3,we decrease bad word to 1 which is wrong i think
we have already calculated for index 0 to count-1 i.e 2 and in second we start i=0 and j=count(3) here i still has the prev value bcz it has to be excluded and j is already included if we start as i=1 then we would be excluding 1 but in this case we have to exclude 0 and j is already at 3 9
My code gives TLE in gfg , I have applied same concept as yours. [ What could be the reason for this TLE?]
int minSwap(int *a, int n, int k) {
int ans= INT_MAX;
int cnt=0;
for(int i=0; i
This code doesn't give TLE if you add below corner cases for two conditions where no swaps are required
and u should return 0 when u encounter any of the below:
--> if(cnt==0 || cnt==n) return 0;
1. When there are no elements less than or equal to k.
2. If all the elements are less than or equal to k.
@@pavanabhishek2053 yeah its working now , thank you !!!
ji how about, if u could explain in english?
Saying because there are already many youtube channels following babbar sheet in hindi
But no one in english
Yes Dharan, new videos are in English only :)