Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make the Array Alternating

med
30 min
Try to solve the Minimum Operations to Make the Array Alternating problem.

Statement

You are given a 00 indexed array of positive integers nums.

The array nums is considered alternating if:

  • nums[i] is equal to nums[i - 2] for all 2≤i<2 \leq i < nums.length

  • nums[i] is not equal to nums[i - 1] for all 1≤i<1 \leq i < nums.length

In one operation, you can choose any index i and change nums[i] to any positive integer.

Return the minimum number of operations required to make nums alternating.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make the Array Alternating

med
30 min
Try to solve the Minimum Operations to Make the Array Alternating problem.

Statement

You are given a 00 indexed array of positive integers nums.

The array nums is considered alternating if:

  • nums[i] is equal to nums[i - 2] for all 2≤i<2 \leq i < nums.length

  • nums[i] is not equal to nums[i - 1] for all 1≤i<1 \leq i < nums.length

In one operation, you can choose any index i and change nums[i] to any positive integer.

Return the minimum number of operations required to make nums alternating.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤105\leq 10^5