my code is always printing NO in all test cases,please help
problem link= VSTRING Problem - CodeChef
code link = VSTRING Problem - CodeChef
my code is always printing NO in all test cases,please help
problem link= VSTRING Problem - CodeChef
code link = VSTRING Problem - CodeChef
I think there is some problem in the logic/corner cases, so you are getting those errors.I will suggest you to go through following .
Use this and try to rewrite the code.
STEP 1:First push all index where 1 is found.
for(int i=0;i<len;i++)
{
if(s[i]=='1')
{
v.push_back(i);
}
}
Step 2:Check the condition that every pair of adjacent ones is separated by at most C zeros. If No. increase count by 1.
ll n = v.size();
ll cnt=0;
for(ll i=0;i<n-1;i++)
{
if(v[i+1]-v[i]>c+1)
{
cnt++;
}
}
Step 3: Check the above condition between the cyclic ones (ie first 1 from the end and first 1 from start)
if(v.size()!=0 && len-1-v[n-1]+v[0]>c )
{
cnt++;
}
finally if count >=2
if(cnt>=2)
{
cout<<"NO"<<endl;
}
else
cout<<"YES"<<endl;
}
link to full code CodeChef: Practical coding for everyone