#1033

Moving Stones Until Consecutive

specialist · 900 · lc medium +31 · verified · 52.2% accepted · 257 likes · top 42%

Description

Three stones sit at distinct positions on the X-axis: a, b, and c. In one move, pick up an endpoint stone and place it at any unoccupied integer position strictly between the other two.

The game ends when the stones occupy three consecutive positions.

Return [answer[0], answer[1]] where answer[0] is the minimum moves and answer[1] is the maximum moves.

Example 1:

Input: a = 1, b = 2, c = 5
Output: [1,2]
Explanation: Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.

Example 2:

Input: a = 4, b = 3, c = 2
Output: [0,0]
Explanation: We cannot make any moves.

Example 3:

Input: a = 3, b = 5, c = 1
Output: [1,2]
Explanation: Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.

Code

1
2
3