Given two integers n and target, find an array of length n such that:
The absolute values of the elements form a permutation of the integers from n.
The sum of the elements in the array equals target.
Return the lexicographically smallest array that satisfies these conditions. If no such array exists, return an empty array [].
Note: An array
ais lexicographically smaller than an arraybof the same length if, at the first index whereaandbdiffer, arrayahas an element strictly smaller than the corresponding element inb.
Constraints:
n
target
Given two integers n and target, find an array of length n such that:
The absolute values of the elements form a permutation of the integers from n.
The sum of the elements in the array equals target.
Return the lexicographically smallest array that satisfies these conditions. If no such array exists, return an empty array [].
Note: An array
ais lexicographically smaller than an arraybof the same length if, at the first index whereaandbdiffer, arrayahas an element strictly smaller than the corresponding element inb.
Constraints:
n
target