JuniorArrayMath

Find N Unique Integers Sum up to Zero

Given an integer n, return any array containing n unique integers such that they add up to 0.

Example 1
Inputn = 5
Output[-7,-1,1,3,4]
The returned array contains 5 unique integers whose sum is 0; other valid arrays are also accepted.
Example 2
Inputn = 3
Output[-1,0,1]
The array contains 3 unique integers and -1 + 0 + 1 = 0.

Constraints

  • 1 <= n <= 1000

Asked at 6 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate