A sequence of integers is a one-sequence if the difference between any two consecutive numbers in this sequence is -1 or 1 and its first element is 0.
More precisely: a1, a2, ..., an is a one-sequence if:
For any k (1 ≤ k < n): |a[k] - a[k+1]|=1, a=0
n- number of elements in the sequence
s- sum of elements in the sequence
- a one-sequence set/list/array/etc of length
nwith sum of elements
s, if possible
- an empty set/list/array/etc if not possible
8 4, output could be
[0 1 2 1 0 -1 0 1] or
[0 -1 0 1 0 1 2 1]. There may be other possibilites.
3 5, output is empty
, since it cannot be done.
This is a code golf, shortest answer in bytes wins. Submissions should be a program or function. Input/output can be given in any of the standard ways.