The Moving Stones Until Consecutive problem places three stones at distinct positions a, b, c on a number line. In each move, you can pick an endpoint stone and move it to any position strictly between the other two. Find the minimum and maximum number of moves to make the stones consecutive. This Moving Stones Until Consecutive coding problem is a math and brainteaser problem with clean case analysis.
Meta asks this because it tests mathematical case analysis and the ability to reason about a physical process without simulation. The minimum and maximum move counts follow from simple conditions about the gaps between stones. The brainteaser and math interview pattern is directly demonstrated.
Case analysis after sorting. Sort: a ≤ b ≤ c.
(b-a-1) + (c-b-1) (move each stone from one end toward the middle one step at a time, always leaving at least one gap).Stones at [1, 2, 5]. Sorted: a=1, b=2, c=5.
Stones at [3, 5, 10]. Max = 1+4=5. Min = 2 (no gap ≤ 2).
Math brainteaser problems require pen-and-paper reasoning before coding. For "minimum/maximum operations to reach a configuration," work out 3-5 examples by hand to identify patterns. Here: max is straightforward (fill both gaps), minimum requires recognizing when one move is enough (a gap ≤ 2 means you can jump over with one move). Practicing case analysis on small problems sharpens this skill quickly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Bulb Switcher | Medium | Solve | |
| Strictly Palindromic Number | Medium | Solve | |
| Nim Game | Easy | Solve | |
| Vowels Game in a String | Medium | Solve | |
| Check if Number is a Sum of Powers of Three | Medium | Solve |