1 through size (each used exactly once) a zigzag if odd and even numbers strictly alternate: no two neighbors share the same parity.
Sort all zigzags lexicographically (as lists) and return the one at position rank (counting from one). If there are fewer than rank zigzags, return an empty list.
The number of zigzags can be astronomically large, so enumerating them is not an option.size=4, rank=5 → [3, 2, 1, 4]
The valid orders, sorted: [1,2,3,4], [1,4,3,2], [2,1,4,3], [2,3,4,1], [3,2,1,4], [3,4,1,2], [4,1,2,3], [4,3,2,1]. The fifth is [3,2,1,4].
size=3, rank=3 → []
With three numbers only [1,2,3] and [3,2,1] qualify; there is no third one, so the answer is an empty list.
size=5, rank=1 → [1, 2, 3, 4, 5]
size=4, rank=5
[3, 2, 1, 4]
Run checks the first 3 tests in your browser. Submit checks all 98 tests on the server, hidden ones included.