LEBOMBS - Editorial

I got it…i missed the case when n=1…

Your code fails for this configuration


1
5
10101

@mohmum your code fails for 1 1 1 answer should be zero but your code prints 1

Why am I getting Wrong Answer CodeChef: Practical coding for everyone

can someone…anyone tell me whats wrong in my code…It run perfectly in devC and codeblocks
#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
int n,arr[1000],ct=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
if(i==0 && arr[i+1]==0 && arr[i]==0)
{
ct++;
}
else if(i==n-1 && arr[i-1]==0 && arr[i]==0)
{
ct++;
}
else if( i>0 && arr[i]==0 && arr[i+1]==0 && arr[i-1]==0)
{
ct++;
}

    }
    if(ct>0)
    {
        cout<<ct<<endl;
    }
    else
    cout<<0<<endl;

}


// your code goes here
return 0;

}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

you’re so good…thank you so much for replying!!!
Here’s the link of my code…
https://www.codechef.com/viewsolution/28553084

2 Likes

I know :slight_smile:

Thanks!

Consider the testcase:

1
6
000110

(the answer should be 2).

1 Like

the output is 2:frowning_face::frowning_face:
image

Based on your screenshot, you’ve added spaces between all the 0’s and 1’s in the testcase I gave you, for some reason.

Oopsi desy…Got it…
I’ll correct my mistake and let you know the output…

Thanks a lot !!!

1 Like

it run successfully now…without any memory,time limit,or run time errors…PhewwWwww!!!
Thank You !!!

1 Like

https://www.codechef.com/viewsolution/29815721
what is wrong in this code?

try

1
1
0

https://www.codechef.com/viewsolution/29815931
Corrected code.^

how did your code work for n = 2 cases? wouldn’t count be incremented twice?

Example?
It goes in the bottom part only when n is 1. Otherwise it just does whatever your code does.

say i enter 00, wouldn’t count become 2?

Yes?, it’s supposed to be 2.

1 Like

forget it . My bad

fixed it and it worked. thanks man