Skip to content

Practice Minimum Operations to Make the Array Alternating

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2170
LeetCode Problem

Minimum Operations to Make the Array Alternating

Problem Statement

Replace any nums entry with any positive integer in one operation. Return the minimum replacements needed so all even-indexed values are equal, all odd-indexed values are equal, and the two values differ whenever both parities occur.

Source: Minimum Operations to Make the Array Alternating on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [3,1,3,2,4,3]
Output
3

# Example 2

Input
nums = [1,2,2,2,2]
Output
2

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Minimum Operations to Make the Array Alternating.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.