Contiguous Array

Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.

Example 1
Inputnums = [0,1]
Output2
[0, 1] is the longest contiguous subarray with an equal number of 0 and 1.
Example 2
Inputnums = [0,1,0]
Output2
[0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.

Constraints

  • 1 <= nums.length <= 10^5
  • nums[i] is either 0 or 1.

Asked at 14 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate