The TransCompilator

Solved LeetCode program · 811 of 1,000

#1049 · Last Stone Weight II

Medium Array chunk-17.md

Original English source

The stones is a list of 2, 7, 4, 1, 8, and 1. The total is 0.
For each stone in stones.
Add stone to total.

The goal is total divided by 2. The possible is a list of 12 zeros. Set item 0 of possible to 1.
For each stone in stones.
For every step from 0 to goal.
The sum is goal minus step. If item sum of possible is 1 and sum plus stone is at most goal, set item (sum plus stone) of possible to 1.

The best is 0.
For every sum from 0 to goal.
If item sum of possible is 1, set best to sum.

The answer is total minus 2 times best. Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

1