Tap here to switch tabs
Problem
Submissions

Problem: Last Stone Weight

med
30 min
Try to solve the Last Stone Weight problem.

Statement

You are given an array stones where each element represents the weight of a stone. Repeatedly perform the following operation while there are at least two stones remaining:

Select the two stones with the largest weights, say x and y with x <= y. Smash them together:
If x == y, both stones are destroyed.
If x != y, the stone of weight x is destroyed and the stone of weight y becomes a new stone with weight y - x.

Return the weight of the final remaining stone. If no stones remain, return 00.

Constraints:

  • 11 \leq stones.length 30\leq 30

  • 11 \leq stones[i] 1000\leq 1000

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Last Stone Weight

med
30 min
Try to solve the Last Stone Weight problem.

Statement

You are given an array stones where each element represents the weight of a stone. Repeatedly perform the following operation while there are at least two stones remaining:

Select the two stones with the largest weights, say x and y with x <= y. Smash them together:
If x == y, both stones are destroyed.
If x != y, the stone of weight x is destroyed and the stone of weight y becomes a new stone with weight y - x.

Return the weight of the final remaining stone. If no stones remain, return 00.

Constraints:

  • 11 \leq stones.length 30\leq 30

  • 11 \leq stones[i] 1000\leq 1000

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths