Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Parity Alternating

Minimum Operations to Make Array Parity Alternating asks you to change values by one so adjacent parities differ, returning minimum operations and the smallest range among arrays with that cost.

Statement

You are given an integer array nums.

An array is called parity alternating if every pair of adjacent elements has different parities (that is, no two adjacent elements are both even or both odd).

In one operation, you can choose any index i and either increase or decrease nums[i] by 11.

Return an array ans of length 22 where:

  • ans[0] is the minimum number of operations needed to make nums parity alternating.

  • ans[1] is the minimum possible value of max⁡(\max(nums)−min⁡() - \min(nums)) among all parity alternating arrays achievable using that minimum number of operations.

Constraints:

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

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

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Parity Alternating

Minimum Operations to Make Array Parity Alternating asks you to change values by one so adjacent parities differ, returning minimum operations and the smallest range among arrays with that cost.

Statement

You are given an integer array nums.

An array is called parity alternating if every pair of adjacent elements has different parities (that is, no two adjacent elements are both even or both odd).

In one operation, you can choose any index i and either increase or decrease nums[i] by 11.

Return an array ans of length 22 where:

  • ans[0] is the minimum number of operations needed to make nums parity alternating.

  • ans[1] is the minimum possible value of max⁡(\max(nums)−min⁡() - \min(nums)) among all parity alternating arrays achievable using that minimum number of operations.

Constraints:

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

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