Skip to content

Practice Permutations IV

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#3470
LeetCode Problem

Permutations IV

Problem Statement

Given two integers, n and k, an alternating permutation is a permutation of the first n positive integers such that no two adjacent elements are both odd or both even. Return the k-th alternating permutation sorted in lexicographical order. If there are fewer than k valid alternating permutations, return an empty list.

Source: Permutations IV on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 4, k = 6
Output
[3,4,1,2]

# Example 2

Input
n = 3, k = 2
Output
[3,2,1]

# Example 3

Input
n = 2, k = 3
Output
[]

Constraints

1 <= n <= 100
1 <= k <= 10^15

Related LeetCode Problems

Practice more problems similar to Permutations IV.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.