Your code passes all these tests, @GoToLoop:
final int[] values = {}; // empty arrayfinal int[] values = {0}; // one zero valuefinal int[] values = {0, 0, 0}; // several zero valuesfinal int[] values = {1}; // one non-zero valuefinal int[] values = {1, 1, 1}; // several non-zero valuesfinal int[] values = {0, 1, 1}; // zero value firstfinal int[] values = {1, 1, 0}; // zero value lastfinal int[] values = {1, 1, 0, 1, 1, 1}; // longest non-zero sequence at endfinal int[] values = {1, 1, 1, 0, 1, 1}; // longest non-zero sequence at beginning
Another remedy that does work is for @batmm to move the inner conditional block to a particular place, so that it executes even when the longest sequence of non-zero values occurs at the end of the array.