Search⌘ K
AI Features

Solution: Longest Subarray of 1's After Deleting One Element

Explore how to use the sliding window technique to find the longest subarray of 1s in a binary array after removing exactly one element. Understand the two-pointer method to maintain a window containing at most one zero, enabling efficient calculation of the maximum contiguous run of ones. This lesson helps you implement a linear time and constant space solution to a common coding interview problem.

Statement

Given a binary array nums, remove exactly one element from it. Return the length of the longest non-empty subarray consisting entirely of 11's in the resulting array. If no such subarray exists, return 00.

Note: Exactly one element must always be deleted, even if all elements are 11's.

Constraints:

  • 11 \leq nums.length 105\leq 10^5 ...