Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Longest Subarray of 1's After Deleting One Element

Medium
sliding-windowarray

Given a binary array nums, you must delete exactly one element. Return the length of the longest run of 1s in the resulting array.

Input: one line of space-separated 0/1 integers. Output: the maximum length (0 if none).

Example 1
Input:
1 1 0 1
Output:
3

Delete the 0 → [1,1,1].

Example 2
Input:
0 1 1 1 0 1 1 0 1
Output:
5

Delete the middle 0 → run of 5.

Example 3
Input:
1 1 1
Output:
2

You must delete something.

Constraints

  • 1 ≤ nums.length ≤ 10^5
  • nums[i] ∈ {0, 1}
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.