|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-score-triangulation-of-polygon "Minimum Score Triangulation of Polygon") |
| 9 | + |
| 10 | +Next > |
| 11 | + |
| 12 | +## 5049. Moving Stones Until Consecutive II (Medium) |
| 13 | + |
| 14 | +<p>On an <strong>infinite</strong> number line, the position of the i-th stone is given by <code>stones[i]</code>. Call a stone an <em>endpoint stone</em> if it has the smallest or largest position.</p> |
| 15 | + |
| 16 | +<p>Each turn, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.</p> |
| 17 | + |
| 18 | +<p>In particular, if the stones are at say, <code>stones = [1,2,5]</code>, you <strong>cannot</strong> move the endpoint stone at position 5, since moving it to any position (such as 0, or 3) will still keep that stone as an endpoint stone.</p> |
| 19 | + |
| 20 | +<p>The game ends when you cannot make any more moves, ie. the stones are in consecutive positions.</p> |
| 21 | + |
| 22 | +<p>When the game ends, what is the minimum and maximum number of moves that you could have made? Return the answer as an length 2 array: <code>answer = [minimum_moves, maximum_moves]</code></p> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | + |
| 26 | +<p><strong>Example 1:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input: </strong><span id="example-input-1-1">[7,4,9]</span> |
| 30 | +<strong>Output: </strong><span id="example-output-1">[1,2]</span> |
| 31 | +<strong>Explanation: </strong> |
| 32 | +We can move 4 -> 8 for one move to finish the game. |
| 33 | +Or, we can move 9 -> 5, 4 -> 6 for two moves to finish the game. |
| 34 | +</pre> |
| 35 | + |
| 36 | +<div> |
| 37 | +<p><strong>Example 2:</strong></p> |
| 38 | + |
| 39 | +<pre> |
| 40 | +<strong>Input: </strong><span id="example-input-2-1">[6,5,4,3,10]</span> |
| 41 | +<strong>Output: </strong><span id="example-output-2">[2,3]</span> |
| 42 | +We can move 3 -> 8 then 10 -> 7 to finish the game. |
| 43 | +Or, we can move 3 -> 7, 4 -> 8, 5 -> 9 to finish the game. |
| 44 | +Notice we cannot move 10 -> 2 to finish the game, because that would be an illegal move. |
| 45 | +</pre> |
| 46 | + |
| 47 | +<div> |
| 48 | +<p><strong>Example 3:</strong></p> |
| 49 | + |
| 50 | +<pre> |
| 51 | +<strong>Input: </strong><span id="example-input-3-1">[100,101,104,102,103]</span> |
| 52 | +<strong>Output: </strong><span id="example-output-3">[0,0]</span></pre> |
| 53 | + |
| 54 | +<p> </p> |
| 55 | +</div> |
| 56 | +</div> |
| 57 | + |
| 58 | +<p><strong>Note:</strong></p> |
| 59 | + |
| 60 | +<ol> |
| 61 | + <li><code>3 <= stones.length <= 10^4</code></li> |
| 62 | + <li><code>1 <= stones[i] <= 10^9</code></li> |
| 63 | + <li><code>stones[i]</code> have distinct values.</li> |
| 64 | +</ol> |
| 65 | + |
| 66 | +<div> |
| 67 | +<div> |
| 68 | +<div> </div> |
| 69 | +</div> |
| 70 | +</div> |
0 commit comments