Maximum Ones after Modification InterviewBit Code + Examples C++
Вставка
- Опубліковано 9 лют 2025
- Given a binary array A and a number B, we need to find length of the longest subsegment of ‘1’s possible by changing at most B ‘0’s.
A[i]=0 or A[i]=1
Input Format
First argument is an binary array A.
Second argument is an integer B.
Output Format
Return a single integer denoting the length of the longest subsegment of ‘1’s possible by changing at most B ‘0’s.
Example Input
Input 1:
A = [1, 0, 0, 1, 1, 0, 1]
B = 1
Input 2:
A = [1, 0, 0, 1, 0, 1, 0, 1, 0, 1]
B = 2
I don't why she is not that famous....her explanation is way better than every famous youtuber...
couldn't stop myself from commenting, you explained it with such simplicity and clarity.
Best explanation of the problem on the internet!
Crystal clear explanation as always 🙇♂🙇♂
superb clear explanation.
Wow what a great explanation I love u dear ❤️💗🥰
truly amazing, aab nahi bhulunga yeh wala concept🥰
great explanation .. keep posting .I just love it
Thanks for the solution! I solved this with a little bit different approach.
1. keep left and right at the start of the string
2. initialize ones_freq = 0 and result = 0
3. increment right by 1 and check if current character is 1, if yes increment ones_freq by 1
4. while right-left+1 - ones_freq > B (current window has more zeros than we can flip)
4.1 increment left by 1 (shrink window) if A[left] == 1 decrement ones_freq by 1
5. Here we have window satisfying the criteria so take max(result, right-left+ 1)
This approach is basically keeping count of 1 in window and based on difference == allowed flips it is calculating the max size
your explanation is really good
great explanation !!!!
just do it by using Sliding window concept
int Solution::solve(vector &A, int B) {
int count=B;
int left=0;
int right=0;
int n= A.size();
int maxLen=0;
while(right=0)
{
count--;
}
if(count>=0)
{
maxLen= max(maxLen,right-left+1);
}
while(count
best explation I got for this question here thankyou so much for this content
Very Nice Explanation Mam😄😄
never commented on any youtube video but this explanation madee me to, thanks
Nice explanation
Good explanation keep it up
Please make more videos on popular questions.. you can refer to striver SDE sheet medium and hard ones
Explained so easily....
mam could we also do it by recursion by thinking to either include one zero or not and then calculating maximum calculating for that choice
Good Explanation What is Time and Space complexity
Nice explanation, also in order to develop the intuition to solve problems is there any way? Or is this just practice, like solve n number of problems so that if n+1 problem is similar to any problem in those n just think similarly?
Special thanks to alisha's brother who is unable to sleep bcz of these lectures.
💯
After watching first 10mins of your video, this is how I tried to implemented it. My thought process was like to maintain a window.
int findZeroes(int arr[], int n, int m) {
vector zeros;
for(int i=0; i
Why you minus for calculate length
By using queue it is possible to store previous zero
avoid extra space
whats the time complexity
it will be o(2n) at worst ig
complixity will be greater than n
weird explaination. Would have been much easier to understand if you just said you were gonna use sliding point approach
woh bnda peeche so raha hai mooh par takiya laga kar🤣🤣