How do I find a maximum number of consecutive non-zero values in the array?

Hi @batmm ,

First of all you need to break the problem into small pieces :

  • How do you represent the fact that a number is non-zero?

  • What does consecutive mean in an array?

  • If you have to work with arrays, what programming structure are you going to use?

Also you can start to write the type signature of your function :

/**
 * Return the maximum number of consecutive non-zero values in the array 
 */
int maximumConsecutiveNonZero(int[] array) {
  return 0;
}

You can also write the rules down on paper and also make some drawings to try to approach it by hand :wink:

2 Likes