#3854
Minimum Operations to Make Array Parity Alternating
medium · 15.7% accepted · 67 likes · top 0%
Description
You are given an integer array nums.
An array is called parity alternating if for every index i where 0 <= i < n - 1, nums[i] and nums[i + 1] have different parity (one is even and the other is odd).
In one operation, you may choose any index i and either increase nums[i] by 1 or decrease nums[i] by 1.
Return an integer array answer of length 2 where:
- answer[0] is the minimum number of operations required to make the array parity alternating.
- answer[1] is the minimum possible value of max(nums) - min(nums) taken over all arrays that are parity alternating and can be obtained by performing exactly answer[0] operations.
An array of length 1 is considered parity alternating.
Solution