I tried to do the following, but in some situations it only return the first consecutive non-zero value but not the longest one. What might be the problem?
int maximumConsecutiveZero(int[] array) {
int count = 0;
int maximum = 0;
for (int i=0; i<array.length; i++) {
if (array[i] != 0) {
count++;
} else {
if (count > maximum) {
maximum = count;
}
count = 0;
}
}
return maximum;
}