Practice Last Stone Weight
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Repeatedly choose the two heaviest stones. If their weights match, remove both. Otherwise replace them with one stone whose weight is their positive difference. Continue until at most one stone remains, and return its weight or 0 when none remain.
Source: Last Stone Weight on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
stones = [2,7,4,1,8,1]
Output
1
# Example 2
Input
stones = [1]
Output
1
Constraints
1 <= stones.length <= 30
1 <= stones[i] <= 1000
Related LeetCode Problems
Practice more problems similar to Last Stone Weight.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.