← Back to challenges

List with Zero Sum

PythonHardarraysconditionsmath

Instructions

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

Examples

list_with_zero_sum(5) ➞ [-7, -1, 1, 3, 4] or [-5, -1, 1, 2, 3] or [-3, -1, 2, -2, 4]

list_with_zero_sum(3) ➞ [-1, 0, 1]

list_with_zero_sum(1) ➞ [0]

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.