Tap here to switch tabs
Problem
Submissions

Problem: Last Stone Weight II

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

Statement

You are given an integer array stones, where stones[i] represents the weight of the ithi^{th} stone.

A game is played as follows: on each turn, any two stones are selected and smashed together. Given two stones with weights x and y where x <= y, the outcome is:

  • If x == y, both stones are destroyed.

  • If x != y, the stone of weight x is destroyed, and the stone of weight y is replaced with a new stone of weight y - x.

The game ends when at most one stone remains.

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

Constraints:

  • 11 \leq stones.length 30\leq 30

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

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 II

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

Statement

You are given an integer array stones, where stones[i] represents the weight of the ithi^{th} stone.

A game is played as follows: on each turn, any two stones are selected and smashed together. Given two stones with weights x and y where x <= y, the outcome is:

  • If x == y, both stones are destroyed.

  • If x != y, the stone of weight x is destroyed, and the stone of weight y is replaced with a new stone of weight y - x.

The game ends when at most one stone remains.

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

Constraints:

  • 11 \leq stones.length 30\leq 30

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

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