#3854
Minimum Operations to Make Array Parity Alternating
expert · 1220 · lc medium +32 · 15.7% accepted · 67 likes · top 0%
Description
Given an integer array nums, an array is parity alternating when every adjacent pair has opposite parity (one even, one odd). In a single operation you may add or subtract 1 from any element. Return an integer array answer of length 2 where answer[0] is the minimum operations needed to achieve parity alternation, and answer[1] is the minimum possible value of max(nums) - min(nums) over all parity-alternating arrays reachable in exactly answer[0] operations. An array of length 1 is always parity alternating.
Code
1
2
3