Binary Subarrays With Sum | 2 Approaches | Detailed Explanation | Leetcode 930 | codestorywithMIK

  Рет қаралды 9,979

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 66
@codestorywithMIK
@codestorywithMIK 8 ай бұрын
Correction : This is 15th Video Of Sliding Window Playlist As you might have seen the news on my Community post. Hence the delay in upload today. Since you are like my friends & family so I decided to share with you too. Thank you all for your condolences. Hope this video helps. Similar Problems : Leetcode - 560 & Leetcode - 1074 : kzbin.info/www/bejne/Y4S6o61vZc92i68
@souravjoshi2293
@souravjoshi2293 8 ай бұрын
🙏 Take care
@thekindspill
@thekindspill 8 ай бұрын
What happened ? I hope everything is fine
@aws_handles
@aws_handles 8 ай бұрын
Take care 🙏🏻 My condolences 💐
@ugcwithaddi
@ugcwithaddi 8 ай бұрын
My condolences 🙏🏻
@wearevacationuncoverers
@wearevacationuncoverers 8 ай бұрын
So sorry to hear for your loss. Please take care.
@gauravbanerjee2898
@gauravbanerjee2898 8 ай бұрын
I have never seen anyone in the community explaining a question with this much simplicity. Thank you so much bhaiya ❤❤ So sorry for your loss, take care ❤
@ankanbrahmachary6581
@ankanbrahmachary6581 8 ай бұрын
so sorry for your loss.. but hats off to you for making every problem so easy by turning it into stories .. thanks for the crystal clear explanation
@kunalpatil.24
@kunalpatil.24 8 ай бұрын
What loss ?
@bhuppidhamii
@bhuppidhamii 8 ай бұрын
no one teaches like u
@rithickchowdhury7116
@rithickchowdhury7116 8 ай бұрын
2nd approach hi pehle dimaag ma aya bt self doubt ka wajah sa lga Brute force ho jayega iss liya chorr diya tha and apka video dekhna lga😅
@mukhritgupta8596
@mukhritgupta8596 8 ай бұрын
By far the best explanation I have come across on YT
@LogicArena01
@LogicArena01 8 ай бұрын
Thanks man. Your style of teaching never disappoints me, a lot of thanks to you ..
@AnkitMeena-d7o
@AnkitMeena-d7o 2 ай бұрын
Sir you are the best teacher 😊 I ever found. I have subscribed to you with all my email id
@wearevacationuncoverers
@wearevacationuncoverers 8 ай бұрын
You are a true gem mik. no one can beat your level of explanation. please take care and may god give strength to you and your family.
@madhurmittal943
@madhurmittal943 8 ай бұрын
Sir you are teaching really great I watch your videos everyday and they are so good...I really appreciate it and hope you keep uploading them daily please
@EB-ot8uu
@EB-ot8uu 8 ай бұрын
fantastic explanation. I will complete your sliding window playlist this weekend. thanks a lot
@ishaansharma6553
@ishaansharma6553 8 ай бұрын
bhaiya my condolences , hats of too you bhaiya even in such a situation you are posting videos , i want to be like you 😇
@harsh.jain22
@harsh.jain22 8 ай бұрын
why condolences ? what happened 😥?
@ishaansharma6553
@ishaansharma6553 8 ай бұрын
@@harsh.jain22 bhaiyas nanaji got expired
@gursimransingh3707
@gursimransingh3707 8 ай бұрын
very nice explanation
@risky_0772
@risky_0772 8 ай бұрын
Watched multiple solutions for 560 as well as 930 but no one explained the hashmap logic as clearly as you, awesome teaching !
@codestorywithMIK
@codestorywithMIK 8 ай бұрын
❤️🙏
@souravjoshi2293
@souravjoshi2293 8 ай бұрын
thank you so much for your detailed explanations. always the best.
@pranjalpandey3077
@pranjalpandey3077 8 ай бұрын
hats off to you bhaiya :)
@DevOpskagyaan
@DevOpskagyaan 8 ай бұрын
Best explanation
@kunalpatil.24
@kunalpatil.24 8 ай бұрын
Thank You!
@techyou6163
@techyou6163 8 ай бұрын
The first approach is also very similar to remove zero sum lists
@umeshbisht1054
@umeshbisht1054 8 ай бұрын
Thanku bhaiya ❤
@sudhanshushekhar4222
@sudhanshushekhar4222 8 ай бұрын
Excellent explanation ❤
@tutuimam3381
@tutuimam3381 8 ай бұрын
Thanks ❤❤❤❤❤❤❤❤
@simnidhnidh9122
@simnidhnidh9122 3 ай бұрын
both approaches are good but second one with sliding window is super easy so can i just do it with 2nd approach only and skip 1st approach?
@kmr3573
@kmr3573 7 ай бұрын
and what about this example [0,0,0,1,1,0] and goal =2 ????
@kajalhargunani6757
@kajalhargunani6757 4 ай бұрын
Hi, Please explain Count Subarrays With More Ones Than Zeros
@maritime_business
@maritime_business 8 ай бұрын
Sliding window approach was confusing! Why did we add zeros here if(sm==k) res+=1+zero; and not before making zero=0 i.e. here-> if(nums[i]==0) zero++; else {res+=zero; zero=0;} shouldn't we add zeros before reinitializing zero to 0 what if for any test case zero count resets before reaching the below condition ? (i tried its giving wrong answer i know but looking at the code it makes sense to add zero count before reinitializing zero to 0)
@pragatidas2910
@pragatidas2910 8 ай бұрын
Sir, Can you please solve codeforces questions like those on binary search space and the atcoder dp sheet. That would be very helpful because no one explains the way you do. Thanks a lot in advance.
@deepanshuverma6237
@deepanshuverma6237 5 ай бұрын
Hey all, Though mik tried his best and un-intentionally missed some cases so not blaming him. but here the explanationa and written code are different ep: nums = [0,1,0,0,1] , goal = 1 ans is 9 .
@solosanskar490
@solosanskar490 8 ай бұрын
Bhaiya priority queue ka comparator ka concept video le aaao please
@shabananoor9423
@shabananoor9423 8 ай бұрын
❤❤
@akworld2739
@akworld2739 6 ай бұрын
your code and dry run is totally different because your i is also move with j
@codestorywithMIK
@codestorywithMIK 6 ай бұрын
Hi there, Can you share where exactly your are pointing? It will help me to correct. Thank you ❤️
@akworld2739
@akworld2739 6 ай бұрын
@@codestorywithMIK 35:48 inner while loop condition your i also move with j
@mohnishkumar6847
@mohnishkumar6847 8 ай бұрын
From where to study sliding window?
@codestorywithMIK
@codestorywithMIK 8 ай бұрын
Sliding Window is a small concept. But qs can be of different levels. So solving different qns will help - kzbin.info/aero/PLpIkg8OmuX-J2Ivo9YdY7bRDstPPTVGvN&si=YsGUj8rqeDSWLfe2 Will add more in this playlist soon
@mohnishkumar6847
@mohnishkumar6847 8 ай бұрын
@@codestorywithMIK so I should directly start solving problems right? Just curious to know how you get to the approach? Any pattern?
@codestorywithMIK
@codestorywithMIK 8 ай бұрын
@mohnishkumar6847 Like I mentioned there are similar patterns in which sliding window problems fall. See my pinned comment for similar problem. The more you solve the more you will understand about it.
@aryanZzz..
@aryanZzz.. 8 ай бұрын
Bhaiya plz make video on leetcode 2831,also explain one thing that sb logo ne is question me explain nhi kiya jb window ka size reduce kiya hai tb agar maximum frequency wala element out of window jaa rha h tb bhi maxf(count of most frequent element in that window) ko same he rkha h reduce nhi kiya?? bohot confusion hora h isme
@ShivamTh405
@ShivamTh405 8 ай бұрын
class Solution { public: int longestEqualSubarray(vector& nums, int k) { int n = nums.size(); int maxFreq = 0; unordered_map mp; int i=0,j=0; while(j k) { mp[nums[i]]--; i++; } j++; } return maxFreq; } };
@ShivamTh405
@ShivamTh405 8 ай бұрын
is code ko dry run krke dekho smjh aa jaega yahn par hme at most k elements ko remove krna hai (0 elements bhi remove kr skte hai) window sirf isliye bna rahe hai taki ye pta chl ske agr kisi window mai maximum freq koi previous maximum frequency se jyda aa gyi or us window mai k ya usse kam elements hai to ham us window wali freq ko consider kr skte hai Eg: 44412335, k=2 pehle j 4th index(element 2) tak move krega kyuki yahn tak sirf two different elements hai (1 and 2) , iske baad jab j 3 pe jaega tab different elements ka count 3 ho jaega isliye window ka size reduce krna hai lekin maxFreq[i] ko minus nahi krna hai, kyuki ye possbility bhi hai ki aage koi jyda max freq na mile, us case mai hamara answer 3 (444) wala subarray hoga in 2 test cases pe dry run kro smjh aa jaega 4441233335 k=2 44413231335 k=2
@aryanZzz..
@aryanZzz.. 8 ай бұрын
@@ShivamTh405 bhai kuch smjh nhi aya
@ShivamTh405
@ShivamTh405 8 ай бұрын
​@@aryanZzz.. dry run kro bhai line by line code ko tab smjh ayega
@sanjaybhatt60
@sanjaybhatt60 2 ай бұрын
I think its not going to work for this case [0,1,1,1,1] and goal = 3
@kanishkkala16
@kanishkkala16 8 ай бұрын
Bhai log yeh btao How is this different from cnt of subarrays with sum k, is it because this one only contains nums more than 0 and so. Why can't we apply sliding window on subarrays with sum k and why can we apply sliding window on this one, basically tell me the 'whysss'
@souravjoshi2293
@souravjoshi2293 8 ай бұрын
This is exactly same as Leetcode-560 (subarrays with sum k). If you see, the code is exactly same as Leetcode-560. Copy paste the same code in 560, it passes all. Now, Coming to sliding window, In a standard sliding window approach, once the window_sum reaches the target (k), the standard algorithm involves simply moving the i pointer of the window forward to potentially find more subarrays. But in this case, Including a zero element in the subarray won't change the sum. As a result, even if the window_sum reaches the target (k) initially, we might miss further subarrays that also meet the goal by simply shrinking the window (moving i to right) as long as the sum remains equal to the goal. This is because the presence of zeros creates the possibility of combining them with elements encountered later to reach the target(k).
@kanishkkala16
@kanishkkala16 8 ай бұрын
@@souravjoshi2293 yes yes, I did apply the pre sum, hash map thing on this my self, I was asking more for the sliding window which u have somewhat explained well, thnx🙌
@wearevacationuncoverers
@wearevacationuncoverers 8 ай бұрын
@@souravjoshi2293thanks
@shivanshagarwala5836
@shivanshagarwala5836 8 ай бұрын
sliding window is not possible in other one. because of negative number (which will make entire shift left end shifting useless to shrink the size.)
@saurabhKumar-hj6yp
@saurabhKumar-hj6yp 8 ай бұрын
❤❤
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН
I thought one thing and the truth is something else 😂
00:34
عائلة ابو رعد Abo Raad family
Рет қаралды 9 МЛН
Как Я Брата ОБМАНУЛ (смешное видео, прикол, юмор, поржать)
00:59
Leetcode 2542 : Maximum Subsequence Score (Medium)
9:48
TechieGanesh
Рет қаралды 671
⚡️NEWS | RUBLE COLLAPSE | STRIKE ON CRIMEA | PUTIN IN KAZAKHSTAN
10:34
Ходорковский LIVE
Рет қаралды 196 М.
C Programming Tutorial for Beginners
3:46:13
freeCodeCamp.org
Рет қаралды 14 МЛН
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН