Trains the technique from
LeetCode 1304Find N Unique Integers Sum up to ZeroThis 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.
Choose n different whole numbers, positive, negative or nothing at all, that add up to nothing.
Return them in increasing order. Where several choices work, return the one whose numbers are as large as they can be, compared from the front: its first number is the largest any valid choice can start with, then its second is the largest given that, and so on.
Example 1
Two pairs of opposites, taken at the smallest sizes going, so one against minus one and two against minus two.
Example 2
Three pairs of opposites use six of the seven numbers, and the one left over has to be nothing, since everything else already cancels.
Example 3
A single pair of opposites, and the smallest sizes going are one and minus one.
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 sum_zero(n: int) -> list[int]:public int[] sumZero(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.