Stones Into a Row
Stones lie on different whole positions of a line, and stones lists the positions. The stone on the smallest position and the stone on the largest position are the end stones. One move picks up an end stone and puts it on a free position where it is no longer an end stone, that is, somewhere between two other stones.
The game stops when no move is possible, which happens exactly when the stones lie on positions in a row. Return [fewest, most]: the fewest and the most moves the game can take.
Example 1
Fewest: move the 3 to 7, and the stones lie on 6, 7, 8. Most: move the 8 to 5, then the 6 to 4.
Example 2
The stones are in a row already.
Constraints
3 <= len(stones) <= 2001 <= stones[i] <= 10**9, all different
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Two pointers problems
- Stretches Between Two BoundsHard
- Busy WindowsBeginner
- Change Over k DaysBeginner
- Common StartBeginner
- Fixes to Make a MirrorBeginner
- Flip a StretchBeginner
- Fold and AddBeginner
- Lighten the ShelfBeginner