Practice/Microsoft/Leetcode 485. Max Consecutive Ones
CodingMust
You are given an array containing only binary values (0s and 1s). Your task is to find the length of the longest contiguous subsequence of 1s within the array.
For example, if the array contains several groups of consecutive 1s separated by 0s, you need to identify which group is the longest and return its length.
Example 1:
Input: [1, 1, 0, 1, 1, 1] Output: 3 Explanation: The longest sequence of consecutive 1s is [1, 1, 1] at the end, which has length 3
Example 2:
Input: [1, 0, 1, 1, 0, 1] Output: 2 Explanation: The longest sequence of consecutive 1s is [1, 1] in the middle, which has length 2
Example 3:
Input: [0, 0, 0] Output: 0 Explanation: There are no 1s in the array, so the answer is 0
Example 4:
Input: [1, 1, 1, 1, 1] Output: 5 Explanation: The entire array is a sequence of 1s, so the answer is 5