My issue
Check for both type conversion (s to all 1 and s to all 0)
if(adjacent char are same they need to change, then Change them to other(0->1 or 1->0)as per require.
After operation check transformed string if any two adjacent char are not same return zero.why this approach is wrong.
My code
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool sol(int n,string s,char c1,char c2){
for(int i=0;i<n-1;i++){
if(s[i]==s[i+1]&&s[i]==c1)
s[i]=s[i+1]=c2;
}
for(int i=0;i<n-1;i++){
if(s[i]!=s[i+1])
return 0;
}
return 1;
}
int main(){
int t;cin>>t;
while(t--){
int n;cin>>n;
string s;
cin>>s;
if(sol(n,s,'0','1')||sol(n,s,'1','0'))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
Problem Link: ADJFLIP Problem - CodeChef