Ctrl K

Tightest Zero-Sum Set

Easy
You are given an integer size. Build a set of size pairwise distinct integers that add up to zero, keeping the largest absolute value in the set as small as possible. It can be shown that such a set is unique. Return its numbers in any order.
Example 1
size=4 → [1, -1, 2, -2]

Four distinct numbers summing to zero fit in [-2, 2]: 1, -1, 2, -2. The range [-1, 1] holds only three integers, so it is not enough.

Example 2
size=5 → [1, -1, 2, -2, 0]

With a bound of 2, all five integers from -2 to 2 are needed, zero included.

Example 3
size=1 → [0]
Constraints
  • 1 ≤ size ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board Easy
loading Python…
Input
size=4
Expected
[1, -1, 2, -2]

Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.