1040. Moving Stones Until Consecutive II
https://leetcode.com/problems/moving-stones-until-consecutive-ii
Description
There are some stones in different positions on the X-axis. You are given an integer array stones
, the positions of the stones.
Call a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and move it to an unoccupied position so that it is no longer an endpoint stone.
In particular, if the stones are at say,
stones = [1,2,5]
, you cannot move the endpoint stone at position5
, since moving it to any position (such as0
, or3
) will still keep that stone as an endpoint stone.
The game ends when you cannot make any more moves (i.e., the stones are in three consecutive positions).
Return an integer array answer
of length 2
where:
answer[0]
is the minimum number of moves you can play, andanswer[1]
is the maximum number of moves you can play.
Example 1:
Example 2:
Constraints:
3 <= stones.length <= 104
1 <= stones[i] <= 109
All the values of
stones
are unique.
ac
Last updated