Input: position =[1,2,3]Output: 1Explanation: First step: Move the chip at position 3 to position 1with cost =0.Second step: Move the chip at position 2 to position 1with cost =1.Total cost is1.
Example 2:
1
2
3
Input: position =[2,2,2,3,3]Output: 2Explanation: We can move the two chips at position 3 to position 2. Each move has cost =1. The total cost =2.
The cost to move a chip depends on whether it moves between even and odd positions. Moving by 2 (even steps) is free, so all chips on even positions can be grouped together at zero cost, and similarly for odd positions. The only cost is moving chips between even and odd positions, which costs 1 per chip. Thus, the minimum cost is moving the smaller group (even or odd) to the other.