Imagine you have stones scattered along a number line. Your goal is to move them until they form consecutive positions (like 5, 6, 7).
Here's the catch: You can only move endpoint stones - the leftmost or rightmost stones in your collection. When you move a stone, it must land in an unoccupied position and no longer be an endpoint.
For example, with stones at [1, 2, 5], you cannot move the stone at position 5 anywhere because it would still remain the rightmost stone!
The puzzle ends when all stones are in consecutive positions. Your task is to find both the minimum and maximum number of moves possible.
Input: An integer array stones representing positions on the X-axis
Output: An array [min_moves, max_moves]
Input & Output
Constraints
- 3 โค stones.length โค 104
- 1 โค stones[i] โค 109
- All values in stones are unique
- At least 3 stones are required for the game to be interesting