n (each exactly once) so that no number stands between two others whose average it is. In other words, for any positions i < k < j it must hold that 2 · a[k] ≠ a[i] + a[j].
There are many such orders, so return this one:
- for n = 1 it is [1];
- otherwise all the odd numbers come first, then all the even ones. The odd numbers follow the order built for ⌈n/2⌉ with every x replaced by 2x − 1; the even numbers follow the order for ⌊n/2⌋ with every x replaced by 2x.
Return that order. Think about why it really has no average in between.n=5 → [1, 5, 3, 2, 4]
The odd numbers 1, 3, 5 come from the order for 3, which is [1, 3, 2], by mapping x to 2x − 1: [1, 5, 3]. The even numbers 2, 4 come from the order for 2, [1, 2], by mapping x to 2x: [2, 4]. The result is [1, 5, 3, 2, 4].
n=2 → [1, 2]
The odd 1 first, then the even 2.
n=8 → [1, 5, 3, 7, 2, 6, 4, 8]
n ≤ 1000n=5
[1, 5, 3, 2, 4]
Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.