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

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate