Leetcode Problem 1033. Moving Stones Until Consecutive

1033. Moving Stones Until Consecutive

Leetcode Solutions

Calculating Minimum and Maximum Moves for Stone Game

  1. Sort the positions of the stones in ascending order.
  2. Calculate the gaps between adjacent stones.
  3. Determine the minimum moves:
    • If the stones are already consecutive, min_moves = 0.
    • If there is only one space between any two stones, min_moves = 1.
    • Otherwise, min_moves = 2.
  4. Calculate the maximum moves by subtracting 2 from the total gap between the first and last stone.
  5. Return the array containing min_moves and max_moves.
UML Thumbnail

Direct Calculation of Moves without Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...