Problem
You get an array of integers stones. Each integer is the weight of one stone.
Each turn, take the two heaviest stones. Their weights are x and y, with x <= y. If x == y, both stones break. If x != y, the stone with the weight x breaks, and the other stone gets the weight y - x.
Continue until at most one stone remains. Return the weight of the last stone, or 0 if no stone remains.
Example 1
- Input:
- stones = [5,12,4]
- Output:
- 3
- Explanation:
- First, the stones 12 and 5 make a stone with the weight 7. Then the stones 7 and 4 make a stone with the weight 3.
Example 2
- Input:
- stones = [7,7]
- Output:
- 0
- Explanation:
- The two stones have the same weight. Both stones break, and no stone remains.
Constraints
- 1 <= stones.length <= 30
- 1 <= stones[i] <= 1000
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Avoid Flood in The City
Coding · Array · Binary Search · Greedy
- Design Movie Rental System
Coding · Array · Design · Hash Table
- Find K Pairs with Smallest Sums
Coding · Array · Heap (Priority Queue)
- Find the Safest Path in a Grid
Coding · Array · Binary Search · Breadth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1046. Last Stone Weight
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Apple
Last Stone Weight
Reported date not specified · Source window: 3mo
Source snapshot: Oct 20, 2026
Source frequency score: 51.2. This is not an interview probability.
View sourceSalesforce
Last Stone Weight
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 55.3. This is not an interview probability.
View source