Moving Stones Until Consecutive
We can find the minimum and maximum number of moves to bring the stones into three consecutive positions by analyzing the gaps between the sorted positions of the stones. Here’s how:
 Sort the Positions: Sort the positions
a
,b
, andc
, so that we work with them in ascending order.  Calculate the Gaps: Find the differences between the sorted positions, namely
gap1
andgap2
.  Minimum Moves:
 If both
gap1
andgap2
are 1, then the stones are already consecutive, and the minimum moves are 0.  If either
gap1
orgap2
is 1, or eithergap1
orgap2
is 2, the minimum moves are 1.  Otherwise, the minimum moves are 2.
 If both
 Maximum Moves: The maximum moves are the sum of
gap1  1
andgap2  1
, as each gap can be filled one by one.
Here’s the code:


Explanation:
 Sorting the positions ensures that we are working with them in ascending order.
 By calculating the gaps, we can determine how many positions need to be filled.
 The minimum moves are calculated based on the size of the gaps.
 The maximum moves are determined by the sum of the gaps minus 1 for each.
For the given example a = 1, b = 2, c = 5
, the code will return [1,2]
, corresponding to the minimum and maximum number of moves.