spots[i] is the cell where token i stands. Several tokens may share a cell.
In one move any token can be shifted:
- 2 cells left or right for free;
- 1 cell left or right for 1 coin.
All tokens must end up on the same cell, which you get to choose. Return the minimum number of coins this takes.spots=[2, 4, 5, 7, 9] → 2
The tokens on 5, 7 and 9 reach cell 5 for free in steps of two, the tokens on 2 and 4 reach cell 4 for free and then each pays for one step to 5. The total is 2.
spots=[3, 3, 10] → 1
Gathering on cell 3 is cheapest: the token on 10 walks to cell 4 for free and pays for one step. The answer is 1.
spots=[6] → 0
spots=[2, 4, 5, 7, 9]
2
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.