AI Interview Prep is optimized for larger screens
Please open this on a laptop or desktop (1024px and wider) to use the full editor, whiteboard, and AI coaching surface.
Understand the problem
Restate the problem precisely. Interviewers reward candidates who pause, define the contract, and name the guarantees before coding.
You are given an array of integers `stones` where `stones[i]` is the weight of the `i`-th stone. We are playing a game with the stones. On each turn, we choose the *heaviest two* stones and smash them together. Suppose the heaviest two have weights `x` and `y` with `x ≤ y`. The result of this smash is: if `x == y`, both are destroyed; otherwise, the stone of weight `x` is destroyed and the stone of weight `y` becomes `y - x`. At the end of the game, at most one stone is left. Return the smallest possible weight of the last remaining stone (or 0 if none).
Once you've drafted a response, click Submit for AI review and a senior engineer will critique your reasoning.