Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Alternate Parity

Minimum Adjacent Swaps to Alternate Parity asks you to rearrange an array of distinct integers so odd and even values alternate, using as few adjacent swaps as possible, or indicate that it cannot be done.

Statement

Given an array nums of distinct integers, determine the minimum number of adjacent swaps required to rearrange the array such that the parity of the elements alternates throughout the array.

An array has alternating parity if no two adjacent elements have the same parity.

Return the minimum number of adjacent swaps needed to achieve this configuration, or return −1-1 if it is impossible.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • All elements in nums are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Alternate Parity

Minimum Adjacent Swaps to Alternate Parity asks you to rearrange an array of distinct integers so odd and even values alternate, using as few adjacent swaps as possible, or indicate that it cannot be done.

Statement

Given an array nums of distinct integers, determine the minimum number of adjacent swaps required to rearrange the array such that the parity of the elements alternates throughout the array.

An array has alternating parity if no two adjacent elements have the same parity.

Return the minimum number of adjacent swaps needed to achieve this configuration, or return −1-1 if it is impossible.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • All elements in nums are distinct.