Max Consecutive Ones III | Leetcode June Challenge | Leetcode 1004 | Approach + Code | C++ | Python
Vložit
- čas přidán 28. 06. 2021
- C++ Code Link : github.com/Ayu-99/Data-Struct...
Python Code Link: github.com/Ayu-99/Data-Struct...
Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)
#leetcode
#leetcodeJuneChallenge
#interviewpreparation
Max Consecutive Ones III solution
Max Consecutive Ones III Leetcode
Max Consecutive Ones III C++
Max Consecutive Ones III C++ Hindi
Max Consecutive Ones III Hindi
Checkout the series: 🔥🔥🔥
👉 Recursion : • Recursion
👉 Stack and Queue : • Stack And Queue
👉 Greedy : • Greedy
👉 Leetcode contests : • Leetcode contests
👉 Leetcode June Challenge : • Leetcode June Challenge
LIKE | SHARE | SUBSCRIBE 🔥🔥😊
pls make more such videos , u have literally explained this problem so amazingly... thank u
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
Thank you for the detailed explanation!
Really amazing explanation, loved it !!
was half way through your video, but completely understood the concept... thanks Di😄😄😄😄
welcome 😄 glad it was helpful :)
Awsm explaination, best on utube
Great job. Explanation is really clear. After this, I hope I don't mess the implementation again in the interview.
Thanks Rahul 🤗
Thank you for the crystal clear explanation didi :)
thanks a lot.. amazing explanation ❤
Amazing explanation ❤
Very good explanation 👍
thanku mam
nice explanation
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 :)
very well explained
Phli ladki dekho hai jiski coding itni acchi h , very good explanation, keep it up and subscribed👍
nice explanation
Koi chakkar ni🤘🤘
Thanks for explaining so nicely!!
Glad it was helpful!😊
Thanks For Nice explanation.
welcome :)
Very Good Dry run , thanks
thank you Nandini :)
Thanks dii very easy and clear explanation.
welcome, glad it was helpful :)
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 🤗🤩
Shukria ❤
The explaination was really great
Thanks Harsh 🤗
Nice explanation. Thanks!
thank you, glad it was helpful :)
mam your voice is so sweet
great explaination
Thank you 😊
useful
Glad you think so!
thnks amazing explanation
Welcome Rahul, glad u liked it 🤗
thx
thanks di❤
Welcome Divyansh :)
dusre while ki jagah if b chl jata no need to used two whiles
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???
to draw do you use mouse only or graphics tablet or you have touch screen ?
I use external mouse :)
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
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
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
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. 😃
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👍🏻
nice explanation
thank you, glad it was helpful :)