Loading problem...
You are given a binary array nums consisting only of 0s and 1s. You must delete exactly one element from the array (the deletion is mandatory, not optional).
After deleting one element, determine the length of the longest contiguous sequence of 1s in the resulting array. If no such sequence of 1s exists after the deletion, return 0.
Key Observations:
nums = [1,1,0,1]3If we remove the element at index 2 (the 0), the resulting array becomes [1,1,1], which contains 3 consecutive 1s. This is the maximum length achievable.
nums = [0,1,1,1,0,1,1,0,1]5Removing the element at index 4 (a 0) transforms the array into [0,1,1,1,1,1,0,1]. The longest contiguous sequence of 1s is [1,1,1,1,1] with length 5.
nums = [1,1,1]2Since all elements are 1s and we must delete exactly one element, the resulting array [1,1] has a maximum consecutive 1s length of 2.
Constraints