Max Consecutive Ones | C++ Placement Course | Lecture 26.2

preview_player
Показать описание
Notes of this Lecture:
Рекомендации по теме
Комментарии
Автор

Bhaiya now aap acche se bata rahe ho this is first question jo mene khud se code kiya 😊

Rohan-ovfr
Автор

ye bhaiya acche se explain nahi karte, didi kafi acche se batati hai..

sanketbhagat
Автор

The problem could have been explained by animation. Its very difficult to understand.

vrashankraom
Автор

Mujhe nhi samaj raha yee bhaiya ka explaination ik he knows what he is doing but the way he explains is hard to understand

artmixfake
Автор

why are you guy's not uploading notes of lecture please upload that too.

sakshammadaan
Автор

yeh bhi sliding window se O(N) me ho jaega.

mihiragrawal
Автор

Hey buddy,
Can you please give some intuition before you directly jump to the solution?

harshgarg
Автор

i have used queue

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int maxOnes(vector<int> v, int k){

queue<int> q ;
int len = 0 ;
int ans = 0 ;

for(int i = 0 ; i < v.size() ; i++){

if(!v[i]){

if(q.size() == k){
len = i - q.front() -1;

q.pop();

}

q.push(i);
}

len++;

ans = max(ans, len);
}

return ans ;
}

int main(){

vector<int> v = {0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1} ;
int k = 3 ;

cout << maxOnes(v, k);

}

jaykapadia
Автор

While condition ke jagah if rakhte tb bhi chal jata any suggestions ?

manishisaxena
Автор

Which software are u using for animation ??
Cau u tell

sunnyrai
Автор

just love the tutorials ... vvvv great work

shubhavvasisht
Автор

What if the input is ? Then the answer would be wrong na? Just asking... coz I got a wrong answer

twinklelight
Автор

when will u upload will be very helpful.

saurabhprasad
Автор

agar j right hai toh usko 0 idexing se kyu start kr rhe hai

praveenanand
Автор

Bhai aapki awaz se mereko dar lagne laga hai

ogbuddha
Автор

can someone explain the j-i+1 concept? it's a little confusing for me.

palakbiswas
Автор

What's the best resource to learn C++ language

babubhaiyasonekalotawaale
Автор

Codes not working for ur previous examples

rahul_ji
Автор

Bhaiya Python Class 12 ki baaki videos bhi daaldo aare hain...

purujindal
Автор

Thank You sir your Logic is good to solve problem BUT

if you are looking for optimize approach ( leetcode )

```class Solution
{
public:
int longestOnes(vector<int> &nums, int k)
{
int i = 0, j;

for (j = 0; j < nums.size(); ++j)
{
if (nums[j] == 0)
k--;
if (k < 0 && nums[i++] == 0)
k++;
}
return j - i;
}
};```

dhruvsakariya