#3470

Permutations IV

master · 1885 · lc hard +32 · 34% accepted · 28 likes · top 11%

Description

An alternating permutation of the first n positive integers is one where no two neighboring elements share the same parity (both odd or both even).

Given n and k, return the k-th such permutation in lexicographic order. If fewer than k alternating permutations exist, return an empty list.

Code

1
2
3