Skip to content

Practice Last Stone Weight II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1049
LeetCode Problem

Last Stone Weight II

Problem Statement

Repeatedly choose any two stones. Equal weights destroy both stones; unequal weights leave one stone whose weight is their positive difference. Continue until at most one stone remains. Choose the pairs to minimize that final weight and return it, using 0 if no stone remains.

Source: Last Stone Weight II 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 = [31,26,33,21,40]
Output
5

Constraints

1 <= stones.length <= 30
1 <= stones[i] <= 100

Related LeetCode Problems

Practice more problems similar to Last Stone Weight II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.