Given an integer array nums, you may replace any element with any integer value in one operation. Return the minimum number of replacement operations required so that the final array has no two adjacent elements equal (i.e., nums[i] != nums[i+1] for all valid i).
Examples
Input: 4
1 1 1 1
Output: 2
Input: 3
1 2 2
Output: 1
Input: 5
3 3 3 3 3
Output: 2
Constraints
1 <= n <= 200000
0 <= nums[i] <= 10^9
Loading...
Results
Not run
Runtime: --Memory: --
4
1 1 1 1
Minimum Replacements to Make Array Alternating
MediumArrayGreedyHash MapCounting
Given an integer array nums, you may replace any element with any integer value in one operation. Return the minimum number of replacement operations required so that the final array has no two adjacent elements equal (i.e., nums[i] != nums[i+1] for all valid i).