Tap here to switch tabs
Problem
Submissions

Problem: Permutations IV

Try to solve the Permutations IV problem.

Statement

Given two integers n and k, return the kextthk^{ ext{th}} lexicographically sorted alternating permutation of the integers from 11 to n. If there are fewer than k valid alternating permutations, return an empty list [].

A permutation of the integers from 11 to n is considered alternating if the parity of adjacent elements alternates, meaning no two adjacent elements are both even or both odd.

Constraints:

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq k ≤1015\leq 10^{15}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Permutations IV

Try to solve the Permutations IV problem.

Statement

Given two integers n and k, return the kextthk^{ ext{th}} lexicographically sorted alternating permutation of the integers from 11 to n. If there are fewer than k valid alternating permutations, return an empty list [].

A permutation of the integers from 11 to n is considered alternating if the parity of adjacent elements alternates, meaning no two adjacent elements are both even or both odd.

Constraints:

  • 1≤1 \leq n ≤100\leq 100

  • 1≤1 \leq k ≤1015\leq 10^{15}