My code solves the problem got correct for input but on submit shows wrong answer.
Problem: https://www.codechef.com/LRNDSA02/problems/PSHOT
My Code:-
#include<iostream>
#include<string>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int N;
cin>>N;
string input;
cin>>input;
int i{0}, j{1}, A{0}, B{0}, ans{0};
for(int r=0; r<N; r++){
A += ((int)input[i]-48);
B += ((int)input[j]-48);
i+=2;
j+=2;
if(A > ((N-r-1)+B) || B > ((N-r-1)+A)){
ans = (r+1)*2;
break;
}
ans = (r+1)*2;
}
cout<<ans<<endl;
}
return 0;
}
Please Help.