|
9 | 9 |
|
10 | 10 | [Next >](https://github.com/openset/leetcode/tree/master/problems/coloring-a-border "Coloring A Border") |
11 | 11 |
|
12 | | -## 5039. Moving Stones Until Consecutive (Easy) |
| 12 | +## 1033. Moving Stones Until Consecutive (Easy) |
13 | 13 |
|
14 | 14 | <p>Three stones are on a number line at positions <code>a</code>, <code>b</code>, and <code>c</code>.</p> |
15 | 15 |
|
16 | | -<p>Each turn, let's say the stones are currently at positions <code>x, y, 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> |
| 16 | +<p>Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position between those endpoints. Formally, let's say the stones are currently at positions <code>x, y, 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> |
17 | 17 |
|
18 | 18 | <p>The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.</p> |
19 | 19 |
|
|
25 | 25 |
|
26 | 26 | <pre> |
27 | 27 | <strong>Input: </strong>a = <span id="example-input-1-1">1</span>, b = <span id="example-input-1-2">2</span>, c = <span id="example-input-1-3">5</span> |
28 | | -<strong>Output: </strong><span id="example-output-1">[1, 2] |
29 | | -<strong>Explanation: </strong>Move stone from 5 to 4 then to 3, or we can move it directly to 3.</span> |
| 28 | +<strong>Output: </strong><span id="example-output-1">[1,2]</span> |
| 29 | +<strong>Explanation: </strong>Move the stone from 5 to 3, or move the stone from 5 to 4 to 3. |
30 | 30 | </pre> |
31 | 31 |
|
32 | 32 | <div> |
33 | 33 | <p><strong>Example 2:</strong></p> |
34 | 34 |
|
35 | 35 | <pre> |
36 | 36 | <strong>Input: </strong>a = <span id="example-input-2-1">4</span>, b = <span id="example-input-2-2">3</span>, c = <span id="example-input-2-3">2</span> |
37 | | -<strong>Output: </strong><span id="example-output-2">[0, 0] |
38 | | -</span><span id="example-output-1"><strong>Explanation: </strong>We cannot make any moves.</span> |
| 37 | +<strong>Output: </strong><span id="example-output-2">[0,0]</span> |
| 38 | +<strong>Explanation: </strong>We cannot make any moves. |
| 39 | +</pre> |
| 40 | + |
| 41 | +<div> |
| 42 | +<p><strong>Example 3:</strong></p> |
| 43 | + |
| 44 | +<pre> |
| 45 | +<strong>Input: </strong>a = <span id="example-input-3-1">3</span>, b = <span id="example-input-3-2">5</span>, c = <span id="example-input-3-3">1</span> |
| 46 | +<strong>Output: </strong><span id="example-output-3">[1,2]</span> |
| 47 | +<strong>Explanation: </strong>Move the stone from 1 to 4; or move the stone from 1 to 2 to 4. |
39 | 48 | </pre> |
40 | 49 |
|
41 | 50 | <p> </p> |
42 | 51 | </div> |
| 52 | +</div> |
43 | 53 |
|
44 | 54 | <p><strong>Note:</strong></p> |
45 | 55 |
|
|
49 | 59 | <li><code>1 <= c <= 100</code></li> |
50 | 60 | <li><code>a != b, b != c, c != a</code></li> |
51 | 61 | </ol> |
| 62 | + |
| 63 | +<div> |
| 64 | +<p> </p> |
| 65 | + |
| 66 | +<div> |
| 67 | +<div> </div> |
| 68 | +</div> |
| 69 | +</div> |
| 70 | + |
| 71 | +### Related Topics |
| 72 | + [[Brainteaser](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md)] |
| 73 | + |
| 74 | +### Hints |
| 75 | +<details> |
| 76 | +<summary>Hint 1</summary> |
| 77 | +For the minimum: We can always do it in at most 2 moves, by moving one stone next to another, then the third stone next to the other two. When can we do it in 1 move? 0 moves? |
| 78 | + |
| 79 | +For the maximum: Every move, the maximum position minus the minimum position must decrease by at least 1. |
| 80 | +</details> |
0 commit comments