Skip to content

Practice Moving Stones Until Consecutive II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1040
LeetCode Problem

Moving Stones Until Consecutive II

Problem Statement

Stones occupy distinct integer positions. In one move, choose a stone at the smallest or largest occupied position and move it to an empty integer position where it is no longer an endpoint. Continue until all stones occupy consecutive positions. Return [minimumMoves, maximumMoves] over valid ways to finish. Unlike simply moving inside the old endpoints, the moved stone must lie strictly between the new endpoints.

Source: Moving Stones Until Consecutive II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
stones = [7,4,9]
Output
[1,2]

# Example 2

Input
stones = [6,5,4,3,10]
Output
[2,3]

Constraints

3 <= stones.length <= 10^4
1 <= stones[i] <= 10^9
All the values of stones are unique.

Related LeetCode Problems

Practice more problems similar to Moving Stones Until Consecutive II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.