Description
Given a binary array nums, return the size of the longest non-empty subarray containing only 1s after deleting exactly one element.
Examples
Input:
nums = [1,1,0,1]Output:
3Explanation:
Delete 0 for [1,1,1].
Input:
nums = [1,1,1,0,0,1,1,1]Output:
6Explanation:
Delete one 0 to connect [1,1,1] with [1,1,1], forming [1,1,1,1,1,1] of length 6.
Input:
nums = [0,0,0]Output:
0Explanation:
All elements are 0. After deleting one 0, this gives [0,0] which has no 1s, so the longest subarray of 1s is 0.
Constraints
- •
1 ≤ nums.length ≤ 10⁵