#1493
Longest Subarray of 1's After Deleting One Element
pupil · 540 · lc medium +28 · verified · 71.1% accepted · 4,800 likes · top 80%
Description
From a binary array nums, you must remove exactly one element. After the removal, find the length of the longest contiguous subarray consisting entirely of 1s. Return 0 if no such subarray exists.
Example 1:
Input: nums = [1,1,0,1]
Output: 3
Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.
Example 2:
Input: nums = [0,1,1,1,0,1,1,0,1]
Output: 5
Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].
Example 3:
Input: nums = [1,1,1]
Output: 2
Explanation: You must delete one element.
Code
1
2
3