Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Longest Subarray of 1's After Deleting One Element (medium)
On this page

Problem Statement

Examples

Try it yourself

Problem Statement

Given a binary array nums, return the length of the longest non-empty subarray containing only 1's after removing 1 element from the array. Return 0 if there is no such subarray.

Examples

Example 1

  • Input: [1, 1, 0, 0, 1, 1]
  • Expected Output: 2
  • Justification: By removing the first 0, you get [1, 1, 0, 1, 1] and the longest sequence of 1s is [1, 1].

Example 2

  • Input: [1, 1, 0, 1, 1, 1]
  • Expected Output: 5
  • Justification: By removing the first 0, you get [1, 1, 1, 1, 1] which is the longest sequence of 1s .

Example 3

  • Input: [1, 0, 1, 1, 0, 1]
  • Expected Output: 3
  • Justification: By removing the 0 between the first and third 1, you get [1, 1, 1, 0, 1], which has a length of 3.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself