#K21. Longest Subarray Without Zero
Longest Subarray Without Zero
Longest Subarray Without Zero
Given an array of integers, find the length of the longest contiguous subarray that does not contain any zeros. A zero in the array breaks the continuity, so the subarray should be formed from consecutive non-zero elements. This problem tests your ability to iterate through arrays while keeping track of segments that satisfy a condition.
For example, given the array [1, 2, 0, 3, 4, 0, 5, 6], the longest subarray without zero is either [1, 2] or [3, 4], each with length 2.
inputFormat
The input consists of two lines:
- The first line contains an integer n, the number of elements in the array.
- The second line contains n space-separated integers.
outputFormat
Output a single integer — the length of the longest contiguous subarray that does not contain any zeros.
## sample8
1 2 0 3 4 0 5 6
2
</p>