Find the minimum halving operations to make an array alternate in parity.
Unlock detailed company stats for this questionUpgrade
Given an array of positive integers, find the minimum number of operations required to make the array alternate in parity, following either Odd, Even, Odd, Even, ... or Even, Odd, Even, Odd, .... In one operation you can replace any element nums[i] = floor(nums[i] / 2), repeatably on the same element. Example: [6, 12, 5, 10] - the Even-Odd-Even-Odd pattern costs 3 operations; Odd-Even-Odd-Even costs 1, so the answer is 1. [3, 12, 5, 10] is already alternating, so the answer is 0. Constraints: 1 <= nums.size() < 10^5, nums[i] > 0.
Community answers
No answers contributed by the community yet.


