Trains the technique from
LeetCode 1406Stone Game IIIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two graders, Iris and Otto, clear a row of salvaged crates. merits[i] is the signed merit of the crate standing i places from the head of the row: a damaged crate carries a negative merit and still counts against whoever takes it.
Iris goes first and the two then alternate. On a turn the grader on duty takes the first one, two or three crates still standing, in a single block from the head of the row, and adds their merits to a personal score. A turn must take at least one crate, and the row shortens as it goes, so the last grader to move may have fewer than three left to choose from. Play ends when the row is empty.
Both graders know the whole row from the start and both play to finish with the largest personal score they can force, caring about nothing else.
Return "Iris" if she ends with the larger score, "Otto" if he does, and "Draw" if the two scores are level.
Example 1
One line runs: Iris clears 5, -2 and 8, Otto clears 40, and Iris is left with the crate at -6. That ends 5 against 40, so the second grader has the larger score.
Example 2
Iris clears three crates for 21 and the single crate left hands Otto 7.
Example 3
Iris clears all three crates in one turn and finishes on 0, and Otto never gets a move, so he finishes on 0 too.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def salvage_winner(merits: list[int]) -> str:public String salvageWinner(int[] merits)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.