DSAMaster Logo
DSAMaster
BackmediumArrays

Maximum Length Balanced Parity Subarray

Problem Description

Given an integer array nums, return the length of the longest contiguous subarray where the number of odd integers is equal to the number of even integers. If no such subarray exists, return 0.

Example 1
Input
nums = [3, 5, 8, 2, 7]
Output
4

Explanation: The subarray [5, 8, 2, 7] contains two odd integers (5, 7) and two even integers (8, 2). The length is 4.

Example 2
Input
nums = [1, 2, 3, 4, 6]
Output
4

Explanation: The subarray [1, 2, 3, 4] has two odd and two even integers, resulting in length 4.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^9
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute