Tap here to switch tabs
Problem
Submissions

Problem: Moving Stones Until Consecutive II

med
30 min
Try to solve the Moving Stones Until Consecutive II problem.

Statement

There are stones placed at distinct integer coordinates along a number line, represented by the integer array stones.

A move consists of selecting an endpoint stone (the stone located at either the minimum or maximum position) and placing it onto an unoccupied position such that it is no longer an endpoint stone. The game finishes when no valid moves remain, which happens when all stones occupy consecutive positions.

Return an array answer of length 22 where answer[0] is the minimum number of moves and answer[1] is the maximum number of moves possible until the game finishes.

Constraints:

  • 3≤3 \le stones.length ≤104\le 10^4

  • 1≤1 \le stones[i] ≤109\le 10^9

  • All the values of stones are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Moving Stones Until Consecutive II

med
30 min
Try to solve the Moving Stones Until Consecutive II problem.

Statement

There are stones placed at distinct integer coordinates along a number line, represented by the integer array stones.

A move consists of selecting an endpoint stone (the stone located at either the minimum or maximum position) and placing it onto an unoccupied position such that it is no longer an endpoint stone. The game finishes when no valid moves remain, which happens when all stones occupy consecutive positions.

Return an array answer of length 22 where answer[0] is the minimum number of moves and answer[1] is the maximum number of moves possible until the game finishes.

Constraints:

  • 3≤3 \le stones.length ≤104\le 10^4

  • 1≤1 \le stones[i] ≤109\le 10^9

  • All the values of stones are unique.