forked from codewithshailendra/COYO-IIT-BHU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFLIP
55 lines (33 loc) · 740 Bytes
/
FLIP
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
45
46
47
48
49
50
51
52
53
54
55
vector<int> Solution::flip(string a) {
int n=a.length();
int csum=0,ans=0;
map<char,int>mp;
mp['0']=1;
mp['1']=-1;
pair<int,int>p=make_pair(INT_MAX,INT_MAX);
int start=0;
for(int i=0;i<n;i++)
{
if(csum+mp[a[i]]<0)
{
csum=0;
start=i+1;
}
else
{
csum+=mp[a[i]];
}
if(csum>ans)
{
ans=csum;
p.first=start;
p.second=i;
}
}
vector<int>v;
if(p.first==INT_MAX)
return v;
v.push_back(p.first+1);
v.push_back(p.second+1);
return v;
}