Max Consecutive Ones III - Leetcode 1004 - Sliding Window (Python)

  Рет қаралды 12,458

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 33
@GregHogg
@GregHogg 4 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@LemesaElias
@LemesaElias 6 ай бұрын
The clearest explanation and visualization I've ever seen on sliding windows .....keep them coming.
@GregHogg
@GregHogg 6 ай бұрын
Oh I'm really glad to hear that 😊
@GarouNguyen
@GarouNguyen 4 ай бұрын
Respect must be earned not given, you have my huge respect gregg hog, you are nothing except truth love and real life not explain anything garbage
@GregHogg
@GregHogg 4 ай бұрын
Haha thanks so much 😊
@bhagyashreepani4059
@bhagyashreepani4059 4 ай бұрын
I was searching for a conscised list to practice DSA questions covering all major concepts, and here it is! Thanks alot ! @GregHogg, YOu are doing awsome job and helping millions ! keep it up! I would need more questions from easy to hard level on bit manipulation i feel less confident on this one
@GarouNguyen
@GarouNguyen 4 ай бұрын
You're never truly happy if you deceiving people, I don't care how many money you make, if you're bad person or you trick people, lie people, or do bad things to people, you're will never feel happy, truly happy in your heart, we're intrinsically borned to do the right things to people and you have proved that, I have huge respect for you Greg Hogg, when you have that, you understand that, that's more important than anything else, mind is all and today the truth is the world is getting harder and harder, people's mind is fucked and controlled by those garbage system, you have huge respect from me Greg Hogg, I wish you all the best things in your life with your dreams, with love & truth, who the fuck doesn't gonna to love you? You're so fucking amazing, thank you so much bro I fucking love you and I think people are fucking love you too, so much respect for you bro
@GregHogg
@GregHogg 4 ай бұрын
Awe that's so sweet thank you 🥰
@sangyetenphel
@sangyetenphel 3 ай бұрын
Thank you very much for the explanantion. I was stuck on this problem but you explained it in a very simple and straightforward manner.
@Lil.Mushroom
@Lil.Mushroom 6 ай бұрын
I just came from the reels and i could not be happier
@GregHogg
@GregHogg 6 ай бұрын
Oh glad to hear this helped! :)
@ridheesh4765
@ridheesh4765 4 ай бұрын
You could keep track of the the first zero in the window, that way you wont have to loop to shrink the window when needed
@xinweili5644
@xinweili5644 4 ай бұрын
Very well explained and the example given is helpful. Thanks for the video.
@7oeseven793
@7oeseven793 3 ай бұрын
Man, Ive watched 2 solutions and the condition of while loop still bugs me. Lets say we reach nums_zeros > k, how is the left pointer being a zero, opening more room to flip 0? Arent we already at a 0 witht the right pointer? How would the left pointer being a 0 reduce the amount of zero if the right pointer is at a zero as well? confusing :( edit: nervermind, I understood. The left pointer nums being 0 allows more flips because we're not counting it anymore in the subarray.
@qinyunli152
@qinyunli152 17 күн бұрын
Hi Greg, great videos! Would you mind sharing the tools you are using to explain the question?
@christianjt7018
@christianjt7018 3 ай бұрын
Very clear explanation, thanks!
@hrushirajg9991
@hrushirajg9991 3 ай бұрын
Thank you so much for explaining it so clean !
@bhuvanachandrag5589
@bhuvanachandrag5589 4 ай бұрын
Hi Greg, Thanks for the amazing video and explanation. I have a quick question on the code implementation. On line 12, I do not think the while loop runs more than once. Because we are flipping one zero at a time with the help of the condtion above it (Line 9). Example, if we have flipped 3 zeroes and k = 2 and our intention is to get back one zero (num_zeroes -= 1), we run through the while loop to decrement. But here, after the first iteration of while loop, the condition evaluates to false (2 > 2). This is because we incremented num_zeroes from 2 to 3 (We are flipping one zero at a time). So, my question is to know the intention of selecting a while loop on Line 12. Since, while loop doesn't work for more than one time, I replaced it with a simple if condition. So, Line 12 will become, if (num_zeroes > k): num_zeroes -= 1. The code will still work for all the cases. Here's my code: class Solution: def longestOnes(self, nums: List[int], k: int) -> int: left = 0 max_num = 0 num_of_zeroes = 0 for index, num in enumerate(nums): if num == 0: num_of_zeroes += 1 if num_of_zeroes > k: if nums[left] == 0: num_of_zeroes -= 1 left += 1 max_num = max(max_num, index - left + 1) return max_num
@S4ntia60
@S4ntia60 7 ай бұрын
IMHO, sliding window algos are very elegant
@GregHogg
@GregHogg 6 ай бұрын
They really are 😊
@niranjanbhat3949
@niranjanbhat3949 7 ай бұрын
Great video buddy 👏🏻! Would love more such . Can u also cover some math and bit manipulation questions?
@GregHogg
@GregHogg 7 ай бұрын
Will do, and thanks so much 😁
@basic-2-advance
@basic-2-advance 7 ай бұрын
Hi Greg, Nice Explanation.What drawing tool do you use ?
@GregHogg
@GregHogg 7 ай бұрын
Thank you! I use miro :)
@basic-2-advance
@basic-2-advance 7 ай бұрын
@@GregHogg Thanks, Keep up with good work.
@scottcooper6644
@scottcooper6644 3 ай бұрын
Hey Greg, love your videos! please in future dont use 'l' as a variable, use 'left'. a single 'l' looks very similar to '1'
@GregHogg
@GregHogg 3 ай бұрын
That's a great point lol. Thanks so much!!
@quchengpeng6905
@quchengpeng6905 6 ай бұрын
Excellent answer 🎉🎉🎉🎉
@GregHogg
@GregHogg 6 ай бұрын
Very happy to hear it :)
@_4p_
@_4p_ 2 ай бұрын
Great
@nicol8472
@nicol8472 Ай бұрын
big ups
@onurucar1112
@onurucar1112 7 ай бұрын
Amazing content as usual! I enjoy watching your solutions after I try implementing by myself
@GregHogg
@GregHogg 7 ай бұрын
That's awesome, that's a really good way to do it 🙂🙂
Max Consecutive Ones (LeetCode 1004) | Full Solution w/ animations
14:41
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 24 МЛН
Accompanying my daughter to practice dance is so annoying #funny #cute#comedy
00:17
Funny daughter's daily life
Рет қаралды 20 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
Coin Change - Leetcode 322 - Dynamic Programming (Python)
15:27
MAX CONSECUTIVE ONES III | LEETCODE 1004 | PYTHON SOLUTION
8:30
Cracking FAANG
Рет қаралды 12 М.
Sliding Window Technique + 4 Questions - Algorithms
27:25
QuanticDev
Рет қаралды 125 М.
The Truth About Learning Python in 2024
9:38
Internet Made Coder
Рет қаралды 216 М.
Max Consecutive Ones III #leetcode #leetcode75
9:19
DEEPTI TALESRA
Рет қаралды 510
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 675 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 24 МЛН