Minimum Swaps to Group All 1's Together II | 2 Ways | Dry Runs | Leetcode 2134 | codestorywithMIK

  Рет қаралды 11,313

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер
@manibhushankumarsingh5196
@manibhushankumarsingh5196 5 ай бұрын
solved on my own, only possible because i am following you regularly from last 3 months.🙏
@indrajitpal02
@indrajitpal02 5 ай бұрын
Today's problem was very much easy when you figure it out
@AryanVats603
@AryanVats603 5 ай бұрын
Did it myself today!! Sir!
@thesoftwareguy2183
@thesoftwareguy2183 5 ай бұрын
Thanks for the hint, Sir!! Have a Good Day a head!!!
@aws_handles
@aws_handles 5 ай бұрын
you are one of the best tutors no doubt. I have shared your channel to almost everyone I know in coding groups
@abhishekrao8444
@abhishekrao8444 5 ай бұрын
we also be use int ones = accumulate(begin(nums), end(nums), 0); or int ones = count(begin(nums), end(nums), 1);
@yashkalia2311
@yashkalia2311 5 ай бұрын
As our placement interview are approaching,can you create a video on time and space complexity of ds and major algos
@manasdeora4601
@manasdeora4601 5 ай бұрын
best question for interview
@prakharsinha4145
@prakharsinha4145 5 ай бұрын
trust me, you're awesome!
@ganeshjaggineni4097
@ganeshjaggineni4097 5 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@SuryaCharanV
@SuryaCharanV 5 ай бұрын
thx for the effort good explanation.
@naveentmyug
@naveentmyug 5 ай бұрын
great explanation, thanks
@anmolbansal4009
@anmolbansal4009 5 ай бұрын
sir can u make one video for each data structure on time complexity and space complexity where like for graphs u can tell and little explain time complexities of main things like dfs,bfs,dijikstra and other importat questions Please can u make 1 such video of time complexities and space complexities for each data structure.....i m facing a lot of difficulty in time complexities
@yashkalia2311
@yashkalia2311 5 ай бұрын
Yesssss
@aws_handles
@aws_handles 5 ай бұрын
yes please mik
@Mlrit-fg9eo
@Mlrit-fg9eo 5 ай бұрын
keep making detailed explaination videos
@gauravbanerjee2898
@gauravbanerjee2898 5 ай бұрын
Thanks a lot bhaiya ❤❤
@YashMalav-kh1ov
@YashMalav-kh1ov 5 ай бұрын
Sir can you mentions those ques in pinned comment which are simiar to this problem
@RohitKumar-dz8dh
@RohitKumar-dz8dh 5 ай бұрын
Thanks 😊
@ashwint959
@ashwint959 5 ай бұрын
class Solution { public int minSwaps(int[] nums) { int numOfOnes = 0; for (int x : nums) { if (x == 1) numOfOnes += 1; } int numOfZeroes = 0; int min = Integer.MAX_VALUE; int start = 0; for (int end = 0; end < 2 *nums.length; end++) { if (nums[end % nums.length] == 0) { numOfZeroes++; } while (end - start + 1 == numOfOnes) { min = Math.min(numOfZeroes, min); if (nums[start % nums.length] == 0) numOfZeroes--; start++; } } return numOfOnes == 0 ? 0 : min; } } You can do it by counting zeroes as well in the sliding window.. The major trick in this problem is to figure size of the window since K is not given. Here it will be equal to number of ones in the window. Once that is figured out, it is a very easy problem..
@mikasaackerman1401
@mikasaackerman1401 5 ай бұрын
After a long break 🙂❤
@KinjalGupta-ts2cz
@KinjalGupta-ts2cz 5 ай бұрын
5 mins into the video and I coded it myself without using extra space☺. My approach is slightly different: class Solution { public: int minSwaps(vector& nums) { int n=nums.size(); int cntOnes=0; for(int i=0;i
@sauravchandra10
@sauravchandra10 5 ай бұрын
This was easy, but after I saw which topic it belonged to.
@aashutoshsathe8078
@aashutoshsathe8078 5 ай бұрын
thank you sirrr
@doomhead9109
@doomhead9109 5 ай бұрын
size of array can be 10^5 for this problem if we make 0 to 2 * 10^5 travel then it should not pass the all test cases as we can run 10^9 operations in 1 sec. Can you explain like why this is not a problem for us ?
@SaurabhKumar-oz2rh
@SaurabhKumar-oz2rh 5 ай бұрын
❤❤
@aizad786iqbal
@aizad786iqbal 5 ай бұрын
even though I know very little of sliding window was able to code it myself after your explations... with both of the approaches... class Solution { public int minSwaps(int[] nums) { int n = nums.length; //int[] arr = new int[2*n]; int totalOnes = 0; for(int i=0;i
@RishabhChatterjee-fg2gz
@RishabhChatterjee-fg2gz 5 ай бұрын
mik bhai, is tarike question mein kyese figure out karunga, ki ye sliding window ka problem hai, kiyuki sliding window ki pattern hota hai, find subarray of length k, etc... but is question mein kyese karunga, sliding window ka aur patterns discuss koro bhai
@VijaySolanki-jk6wm
@VijaySolanki-jk6wm 5 ай бұрын
more practice will let u know all things bro !!
@aws_handles
@aws_handles 5 ай бұрын
practice practice practice. I had solved a similar problem and hence was able to figure out sliding window
@zebra-er6xc
@zebra-er6xc 5 ай бұрын
@@aws_handles can you share some similar problems like this one
@RishabhChatterjee-fg2gz
@RishabhChatterjee-fg2gz 5 ай бұрын
@@aws_handles Yes, I know practice is only way but I want to know, more types of patterns which are solved using sliding window, like find k length subarray, etc... can you say?
@imPriyansh77
@imPriyansh77 5 ай бұрын
@@zebra-er6xc see problems under leetcode 'similar problems' section in description page
@AsK-kh4ze
@AsK-kh4ze 5 ай бұрын
please also provide code in java.
@izanahmad5705
@izanahmad5705 5 ай бұрын
Here is My solution: int minSwaps(vector &nums) { int n = nums.size(); int totalOnes = count(nums.begin(), nums.end(), 1); int currOnes = count(nums.begin(), nums.begin() + totalOnes, 1); int minSwap = totalOnes - currOnes; int i = 0, j = totalOnes - 1; while (j < 2 * n - 1) { j++; if (nums[j % n]) { currOnes++; } if (nums[i % n]) { currOnes--; } i++; minSwap = min(minSwap, totalOnes - currOnes); } return minSwap; }
@rohanprabhakar1991
@rohanprabhakar1991 5 ай бұрын
I have been doing Daily leetcode for around 250 days but now i don't want to do it. i am not getting any motivation to do it and it leads to losing my consistency. I am loosing the patience i just want to see solution now and also after 5 min i don't want to watch and skip it to direct solution. What can i do i don't want to think by myself as it's not pushing me anymore,i want your opinion now. Help me
@closer9689
@closer9689 5 ай бұрын
I am also in kind of same situation.Don't know why, But i could not solve new problems with enthusiasm. Inspite of knowing that i am not that good enough untill now, I am not feeling to put efforts while solving, and i become impatient while solving problem.
@yogeshwargupta5878
@yogeshwargupta5878 5 ай бұрын
you should try to upload video of gfg ptod also
@harishms5330
@harishms5330 3 ай бұрын
U should try to solve it on your own also
@kumkumslab5811
@kumkumslab5811 5 ай бұрын
int one=0; for(auto &i:nums)if(i==1)one++; int i=0; int j=one-1; int cnt=0; for(int k=i;k
@dayashankarlakhotia4943
@dayashankarlakhotia4943 5 ай бұрын
public int minSwaps(int[]nums){ int cntOnes=0; for(int i=0;i=cntOnes-1) min=Math.min(min,cntOnes-sum); } for(int i=0;i
@Rajdweep
@Rajdweep 5 ай бұрын
yr sliding window ka intuition hi nhi aya...main soch rha tha largest group ko nikalke fir sides ko increase kru...aisa intuition kaise banau itne din hogye fir bhi nhi aya
@zebra-er6xc
@zebra-er6xc 5 ай бұрын
mai bhi largest ones ka group nikal kar try kar raha tha, video dekh ke sliding window ka idea aaya
@ashwint959
@ashwint959 5 ай бұрын
IS anyone having problems running leetcode solutions due to the slowness of the site?
@dayashankarlakhotia4943
@dayashankarlakhotia4943 5 ай бұрын
we can implement it in our windowSize how many min zero. public int minSwaps(int[]nums){ int windowSize=0; for(int num:nums) windowSize+=num; int curZeros=0; for(int i=0;i
@BHONEPIYUSH
@BHONEPIYUSH 5 ай бұрын
Haath beth gaya hai dsa sikhane pe , not many youtubers are like this
@deeptidip9864
@deeptidip9864 5 ай бұрын
Please topic ka approach phle mention mat kiya karo😢 we come here to get overview and poora approach phle pata chal jata🤧
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
I tried to hide the approach in the beginning. I will try to increase the duration of initial part for hiding the topic name. Thank you 🙏😇
@aryansonwani7061
@aryansonwani7061 5 ай бұрын
Atleast 5 min ke baad bataya karo
@ArunBorse-g2k
@ArunBorse-g2k 5 ай бұрын
@@codestorywithMIK it will help mic
@DevOpskagyaan
@DevOpskagyaan 5 ай бұрын
My fear of sliding window is gone. Thanks a lot 🫡
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН