-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxContinuousSeriesOf1's.cpp
More file actions
44 lines (41 loc) · 960 Bytes
/
MaxContinuousSeriesOf1's.cpp
File metadata and controls
44 lines (41 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*Question:
Max Continuous Series of 1s
Asked in:
VMWare
You are given with an array of 1s and 0s. And you are given with an integer M, which signifies number of flips allowed.
Find the position of zeros which when flipped will produce maximum continuous series of 1s.
For this problem, return the indices of maximum continuous series of 1s in order.*/
vector<int> Solution::maxone(vector<int> &A, int B) {
int s=0,e=0;
int cz=0;
int ans=0;
int si=0,ei=0;
int co=0;
while(s<A.size(),e<A.size())
{
if(cz<=B)
{
if(A[e]==0)
cz++;
e++;
}
if(cz>B)
{
if(A[s]==0)
cz--;
s++;
if(s>e)
e=s;
}
if(ans<e-s+1)
{
ans=e-s+1;
si=s;
ei=e;
}
}
vector<int> v;
for(int i=si;i<ei;i++)
v.push_back(i);
return v;
}