Trains the technique from
LeetCode 2035Partition Array Into Two Arrays to Minimize Sum DifferenceThis 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.
A survey barge is trimmed by hanging ballast blocks under its two pontoons. The array blocks carries one trim value per block on board, and there are 2 * n blocks in all. A positive value weighs its pontoon down; a negative value lifts it.
The rigging crew has to hang every block, and each pontoon must finish with exactly n of them under it. The trim of a pontoon is the sum of the values hung under it. Return the smallest gap the crew can leave between the trims of the two pontoons, where the gap is an absolute value and so never negative.
Example 1
One pontoon takes the blocks valued 8 and -2 for a trim of 6; the other takes 5 and 1, also a trim of 6. Both pontoons carry two blocks and the gap is 0.
Example 2
Two blocks hang under each pontoon: 1 and 1 read as a trim of 2, and 1 and 9 read as a trim of 10, so the gap is 8.
Example 3
Three blocks per pontoon. Hanging -7, 6 and 0 on one side gives a trim of -1, and 4, -3 and -1 on the other gives a trim of 0, so the gap is 1.
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 min_trim_gap(blocks: list[int]) -> int:public int minTrimGap(int[] blocks)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.