Problem
You get a binary array nums. A binary array has only the values 0 and 1. You must delete exactly one item from nums.
After the deletion, return the length of the longest subarray that has only 1 items. A subarray is a part of the array with consecutive items. If no such subarray exists, return 0.
Example 1
- Input:
- nums = [1,1,0,1,1,1,0,1]
- Output:
- 5
- Explanation:
- Delete the
0at index 2. Then the first five items are all1.
Example 2
- Input:
- nums = [1,1,1,1]
- Output:
- 3
- Explanation:
- You must delete one item, even when every item is
1.
Example 3
- Input:
- nums = [0,0,1,0]
- Output:
- 1
Constraints
- 1 <= nums.length <= 10^5
- nums[i] is 0 or 1.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1493. Longest Subarray of 1's After Deleting One Element
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source