Understood! thanks. C++ implementation --- //ALGORITHM: Basically we see arr, we see k. Voila!\ //Sliding window problem. Now to tackle this. //We take i=j=0. ans=0 and zerocount=0 //Basically, j will keep on moving till //we our zerocount > k. At that point. //we first do ans = max(ans, j-i+1) //next obv, we need to move i (that is, //sliding the fucking window.) //Now till when? Glad you asked! //We do it until we get a pass! (i.e. our //zerocount becomes equal to k //at that point we simply go back to moving j //untill we see another 0 focring us to incrment //zerocount. Thus the steps repeat) int longestSubSeg(vector &arr , int n, int k){ int i=0, j=0, ans=0, zerocount=0; while(j
Today i visit your channel first time while facing difficulties solving this problem.... really you explained very well dii...now my all doubts are cleared about two pointer approach.....
I think you should explain more clearly, it was a bit complex to understand, i understood the concept, but then how to play with i and j was a bit difficult to comprehend
Hello , can u ecplain why this works ? zeros, l = 0, 0 for r, n in enumerate(nums): zeros += n == 0 if zeros > k: zeros -= nums[l] == 0 l += 1 print(r,l,len(nums)) return r - l + 1
was half way through your video, but completely understood the concept... thanks Di😄😄😄😄
welcome 😄 glad it was helpful :)
Understood! thanks.
C++ implementation ---
//ALGORITHM: Basically we see arr, we see k. Voila!\
//Sliding window problem. Now to tackle this.
//We take i=j=0. ans=0 and zerocount=0
//Basically, j will keep on moving till
//we our zerocount > k. At that point.
//we first do ans = max(ans, j-i+1)
//next obv, we need to move i (that is,
//sliding the fucking window.)
//Now till when? Glad you asked!
//We do it until we get a pass! (i.e. our
//zerocount becomes equal to k
//at that point we simply go back to moving j
//untill we see another 0 focring us to incrment
//zerocount. Thus the steps repeat)
int longestSubSeg(vector &arr , int n, int k){
int i=0, j=0, ans=0, zerocount=0;
while(j
Phli ladki dekho hai jiski coding itni acchi h , very good explanation, keep it up and subscribed👍
pls make more such videos , u have literally explained this problem so amazingly... thank u
Great job. Explanation is really clear. After this, I hope I don't mess the implementation again in the interview.
Thanks Rahul 🤗
Awsm explaination, best on utube
Today i visit your channel first time while facing difficulties solving this problem.... really you explained very well dii...now my all doubts are cleared about two pointer approach.....
glad to hear that :)
Thank you for the crystal clear explanation didi :)
Thank you for the detailed explanation!
Thanks dii very easy and clear explanation.
welcome, glad it was helpful :)
Very Good Dry run , thanks
thank you Nandini :)
Thanks For Nice explanation.
welcome :)
mam your voice is so sweet
I tried this question by myself but couldn't make through some cases nice explanation got to know what I was mistaking.
Glad it was helpful Ankit 🤗🤩
Koi chakkar ni🤘🤘
Very good explanation 👍
thanku mam
nice explanation
Thanks for explaining so nicely!!
Glad it was helpful!😊
Really amazing explanation, loved it !!
For input "111000" and k=1 the answer should be 3 but your code will give 4 since there is no information about the number of 1s.
I think it should be 4 only . Why do you think its going to be 3???
Nice explanation. Thanks!
thank you, glad it was helpful :)
The explaination was really great
Thanks Harsh 🤗
Amazing explanation ❤
very well explained
thanks a lot.. amazing explanation ❤
dusre while ki jagah if b chl jata no need to used two whiles
to draw do you use mouse only or graphics tablet or you have touch screen ?
I use external mouse :)
Shukria ❤
nice explanation
useful
Glad you think so!
Koi chakkar nhi h😊😂
I think you should explain more clearly, it was a bit complex to understand, i understood the concept, but then how to play with i and j was a bit difficult to comprehend
great explaination
Thank you 😊
thnks amazing explanation
Welcome Rahul, glad u liked it 🤗
thx
oyy dii,, its not sliding window
its two pointer method
Oyy geeks, we are maintaing a window having at most k zeros everytime. It's sliding window🙂
@@AyushiSharmaDSA epic reply😂
@@exploringworld6817 😂😂😅
🥸🥸,, your ans is like
I'm justifying my ans with the reason you use 2 pointers🙂.
@@aishwaryarathod5421 Bro, there are different approaches. You can try whichever you like. 😃
Time complexity kya rahegi?
Time : O(n)
Space : O(1)
Atmost we lookup each element twice so
O (2*n)..which is nothing but O(n).
@@shivajibanoth306 yes
thanks di❤
Welcome Divyansh :)
Phir Level add ni kiye😔
I added in thumbnail. Do you want me to add in title?
@@AyushiSharmaDSA okk chlega
@@exploringworld6817 I'll add in title from next time👍🏻
Hello ,
can u ecplain why this works ?
zeros, l = 0, 0
for r, n in enumerate(nums):
zeros += n == 0
if zeros > k:
zeros -= nums[l] == 0
l += 1
print(r,l,len(nums))
return r - l + 1
nice explanation
thank you, glad it was helpful :)