Trains the technique from
LeetCode 2163Minimum Difference in Sums After Removal of ElementsThis 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 meter has written down 3 * n readings in the order they were taken, given as nums.
An auditor strikes out exactly n of the readings, chosen freely. The 2 * n readings still standing keep their original order: the earlier half of them, meaning the first n that survive, is the opening block, and the later half, the last n that survive, is the closing block.
The score of a set of strike-outs is the total of the opening block minus the total of the closing block. This score may be negative. Return the smallest score the auditor can reach.
Example 1
Strike out the last reading, 2. The opening block is 4 and the closing block is 9, so the score is 4 - 9 = -5.
Example 2
Strike out the 3 at position 3 and the 4 at position 5. The survivors in order are 6, 2, 8, 9, so the opening block totals 8 and the closing block totals 17, giving a score of -9.
Example 3
Every reading is 5, so whichever two are struck out both blocks total 10 and the score is 0.
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 minimum_difference(nums: list[int]) -> int:public long minimumDifference(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.