Contest-DSA Learning Series Week-2
Problem-CodeChef: Practical coding for everyone
Can anyone help me in finding out why this code is giving wrong answer?
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int i,n;
cin>>n;
string s;
cin>>s;
int chances=n;
int result=2*n;
int a_score=0,b_score=0;
for(i=0;i<2*n;i+=2)
{
if( a_score>b_score+chances || b_score>a_score+chances)
{
result=i;
break;
}
a_score+=int(s[i])-'0';
b_score+=int(s[i+1])-'0';
chances-=1;
}
cout<<result<<endl;
}
}