Solving Moving Stones Until Consecutive II in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.

The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.

Example 1:

Input: [7,4,9]
Output: [1,2]
Explanation: 
We can move 4 -> 8 for one move to finish the game.
Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game.

Example 2:

Input: [6,5,4,3,10]
Output: [2,3]
We can move 3 -> 8 then 10 -> 7 to finish the game.
Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game.
Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move.

Example 3:

Input: [100,101,104,102,103]
Output: [0,0]

Note:

  1. 3 <= stones.length <= 10^4

  2. 1 <= stones[i] <= 10^9

  3. 3 <= stones.length <= 10^4

  4. 1 <= stones[i] <= 10^9

See the full details of the problem Moving Stones Until Consecutive II at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go