'Why codechef not accepting my correct solution ? my code satisfy every condition and gives correct output
We have to find the maximum length of subarray that gives non-zero product of continuous element of array. eg:
1.)
I/P: 6 1 0 2 3 0 4 O/p: 2
2. I/P: 1 0 O/P: 0
3. I/p: 3 1 0 1 O/p: 1
For the first sample subarray is: {2, 3}.
For the second sample there are no subbarays with non-zero product.
For the third sample subbarays is {1}, (the first element, or the third one).
The above problem is in codechef:https://www.codechef.com/problems/CHEFZOT
I wrote the code and it gives right output everytime. but when I submit it codechef says,it is wrong answer. Pls tell me what's wrong. first line of intput represent the length of array. and second line represent elements of array separated by spaces.
#include <stdio.h>
int main()
{
int l=0,k=0;
int n;
int p=1;
scanf("%d",&n);
int a[n];
int m[n];
int max;
for(int i=0;i<n&&i<10000;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
if(a[i]==0)
{
m[k]=l;
k=k+1;
l=0;
}
else
{
p=a[i]*p;
l++;
}
}
max=m[0];
for(int i=0;i<k;i++)
{
if(m[i]>max)
max=m[i];
}
printf("%d\n",max);
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
