Skip to content

Practice Beautiful Arrangement II

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

Medium#667
LeetCode Problem

Beautiful Arrangement II

Problem Statement

Return any permutation of the integers 1 through n such that the absolute differences between adjacent entries contain exactly k distinct values. Every integer must appear once, and only adjacent differences count toward k.

Source: Beautiful Arrangement II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

1 <= k < n <= 10^4

Related LeetCode Problems

Practice more problems similar to Beautiful Arrangement II.

Review your practice with PhantomCodeAI

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