Code RoomSmallest stone after smashing
MediumPrep Room Coding #87

Smallest stone after smashing

CodingAlgorithms & data structuresMid–Senior~25 min

You have a collection of stones with positive integer weights. In each turn you smash any two stones x and y (x <= y): they both vanish and a new stone of weight y-x appears (if y-x is 0 nothing remains). After repeatedly smashing, at most one stone is left. Return the smallest possible weight of that last stone (0 if none remains). There are at most 30 stones, each of weight at most 100.

Implement
last_stone_weight_ii(stones: list[int]) → int
Examples
in[[2,7,4,1,8,1]]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[2,7,4,1,8,1]]1not run yetsample