Trains the technique from
LeetCode 2170Minimum Operations to Make the Array AlternatingThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A strip of positive readings reads readings. The strip alternates when every two readings that sit two places apart are equal and no two neighbouring readings are equal. A strip of one reading alternates already.
One change replaces a single reading with any positive whole number. Return the fewest changes that leave the strip alternating.
Example 1
The strip already alternates: the even positions all read two, the odd ones all read one, and the two differ.
Example 2
Both sides want to read one, but they must differ, so one side has to change every one of its two readings.
Example 3
The two readings are equal and sit next to each other, so one of them has to change.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def minimum_operations(readings: list[int]) -> int:public int minimumOperations(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.