 All Problems
Longest Subarray of 1s After Deleting One Element
medium
sliding window
arrays
amazon
google

Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1s in the resulting array. Return 0 if there is no such subarray.

Example 1:

Input: 1 1 0 1
Output: 3

Example 2:

Input: 0 1 1 1 0 1 1 0 1
Output: 5

Example 3:

Input: 1 1 1
Output: 2

Constraints:

  • 1 ≤ nums.length ≤ 10⁵
  • nums[i] is 0 or 1

Input format: One line — space-separated binary array.

Output format: Length of longest subarray of 1s after deleting one element.

Run to check your code against the sample cases, or submit to run every case