Ctrl K

Three Stones Close Ranks

Medium
Three stones lie on a number line at the integer points first, second and third (all different). In one move you take an end stone, the leftmost or the rightmost, and put it on any free integer point strictly between the other two stones. The game is over when the stones occupy three adjacent points and no move is left. Return a list of two numbers: the fewest and the most moves the game can take.
Example 1
first=2, second=9, third=4 → [1, 5]

The fastest finish moves the stone from 9 to 3: one move. The longest game takes five moves, inching the stones along so that every one of the five free points gets used: 2→3, 3→5, 4→6, 5→7, 6→8.

Example 2
first=6, second=5, third=7 → [0, 0]

The stones are already side by side, so no move is possible.

Constraints
  • 1 ≤ first, second, third ≤ 100
  • The three numbers are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLamps Left Burning MediumLast Viewer in the Right Seat MediumTake From Any Pile MediumA Mirror in Every Base MediumOR of All Subset Sums Medium
loading Python…
Input
first=2, second=9, third=4
Expected
[1, 5]

Run checks the first 3 tests in your browser. Submit checks all 132 tests on the server, hidden ones included.