java.lang.Object
g1001_1100.s1033_moving_stones_until_consecutive.Solution

public class Solution extends Object
1033 - Moving Stones Until Consecutive.<p>Medium</p> <p>There are three stones in different positions on the X-axis. You are given three integers <code>a</code>, <code>b</code>, and <code>c</code>, the positions of the stones.</p> <p>In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let&rsquo;s say the stones are currently at positions <code>x</code>, <code>y</code>, and <code>z</code> with <code>x < y < z</code>. You pick up the stone at either position <code>x</code> or position <code>z</code>, and move that stone to an integer position <code>k</code>, with <code>x < k < z</code> and <code>k != y</code>.</p> <p>The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).</p> <p>Return <em>an integer array</em> <code>answer</code> <em>of length</em> <code>2</code> <em>where</em>:</p> <ul> <li><code>answer[0]</code> <em>is the minimum number of moves you can play, and</em></li> <li><code>answer[1]</code> <em>is the maximum number of moves you can play</em>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> a = 1, b = 2, c = 5</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Explanation:</strong> Move the stone from 5 to 3, or move the stone from 5 to 4 to 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> a = 4, b = 3, c = 2</p> <p><strong>Output:</strong> [0,0]</p> <p><strong>Explanation:</strong> We cannot make any moves.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> a = 3, b = 5, c = 1</p> <p><strong>Output:</strong> [1,2]</p> <p><strong>Explanation:</strong> Move the stone from 1 to 4; or move the stone from 1 to 2 to 4.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= a, b, c <= 100</code></li> <li><code>a</code>, <code>b</code>, and <code>c</code> have different values.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numMovesStones

      public int[] numMovesStones(int a, int b, int c)