Skip to content

Practice Beautiful Array

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

Medium#932
LeetCode Problem

Beautiful Array

Problem Statement

Return any permutation nums of integers 1 through n with this property: for every i < k < j, 2 * nums[k] must differ from nums[i] + nums[j]. A valid permutation always exists.

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

Examples

# Example 1

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

# Example 2

Input
n = 5
Output
[3,1,2,5,4]

Constraints

1 <= n <= 1000

Related LeetCode Problems

Practice more problems similar to Beautiful Array.

Review your practice with PhantomCodeAI

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