Given an integer n, construct and return an array of n distinct integers such that the sum of all elements is equal to 0. If multiple valid arrays exist, you may return any one of them.
Constraints:
Input: n = 2-int
Output: [1, -1]-List[int]
Explanation: The two integers are distinct and 1 + (-1) = 0.
Input: n = 4-int
Output: [2, -2, -1, 1]-List[int]
Explanation: All values are distinct, and the pairs cancel out: (2 + -2) + (-1 + 1) = 0.
Input: n = 5-int
Output: [-2, -1, 0, 1, 2]-List[int]
Explanation: The array includes 0 (allowed and distinct), and the symmetric values sum to zero: (-2 + 2) + (-1 + 1) + 0 = 0.
Input: n = 1-int
Output: [0]-List[int]
Explanation: The only way to have one integer summing to zero is [0], which is distinct by default.
Input: n = 999-int
Output: [-436, 210, -55, 329, -200, 286, ..., 331]-List[int]
Explanation: Any array of 999 distinct integers whose total sum is 0 is valid (output truncated for readability).
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem: