- Denisse's Newsletter
- Posts
- Day 25
Day 25
Max Consecutive 1's

Hello hello hello,
Welcome back!
Today I wanted to ask something, have you ever had that voice in your head saying damn it, you should know this?
You are solving a problem and can’t concentrate because you are so mad at yourself for not knowing the solution.
It may only be me though.
And then nothing happens, you get more frustrated because you can’t solve the problem. The more we beat ourselves up, the harder it becomes to think clearly and find the answer. It’s a vicious cycle.
Let me in on a little secret; nothing good comes out of being mad at yourself.
I’ve always been hard on myself and still am.
I always think being in a dark spot produces the best results.
But..
It turns out if you are happy you can also be productive and more creative.
Tension and anger may produce a positive experience occasionally, but I promise it was not the best result possible.
So, the next time you find yourself frustrated, try this: stop, take a deep breath in, and slowly exhale. Have a conversation with that critical voice in your head. Tell it, “The harder you are on me, the longer this will take. Let’s work together and make this better.”
Call me crazy (Probably am) but rationalizing with the voice in your head is often the solution, try it, and let me know how it went!
Day 26: 1004. Max Consecutive Ones III
Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.
There are two keywords in this problem; consecutive and k.
Two key elements in this problem are "consecutive" and "k." Given that "k" represents the maximum number of 0's we can flip, the goal is to find the longest sequence of consecutive 1's achievable by flipping at most "k" 0's.
Once you see a pattern, you can not unsee it. (If you need a refresher on the sliding window pattern)
Let’s dive in 🤿 ,
Our window is going to be determined by the number of 0's
we have counted so far. Once we hit k
number of 0’s
our window ends.
The incredible thing about sliding window is that we don’t have to re-calculate the substring again, we only need to sliideeeee our window.
To slide our window we move our left pointer to the right until we find a 0
to “unflip” it. After we “unflip” our 1
back to 0
, we gain back one more flip and we can proceed to move our right pointer, finding more zeros to flip.
In each window, we need to calculate the length of it and update the maximum. To calculate the length of the window :
r - l + 1
At the end of our iteration we return the max between our Max Window and our current window.
Let’s proceed with an example :

Complete solution:
int maxOnes = 0;
int l = 0;
int countOfZero = 0;
for (int r = 0; r < nums.size(); r++) {
if (nums[r] == 0) {
countOfZero++;
}
while (countOfZero > k) {
if (nums[l] == 0) {
countOfZero--;
}
l++;
}
maxOnes = max(maxOnes, r - l + 1);
}
return maxOnes;
}
LIFE LATELY
Got a chance to go to CVPR ( Computer Vision and Pattern Recognition) in Seattle and got to meet a ton of researchers who work with AI from all over the world!
Me at the Weights and Biases + Lambda + Union AI after party 🎉

Have you heard about Blockchain lately? I haven’t. My thoughts on it.
Let’s keep the roll goiiiiing,
See you next Thursday!
Reply