Skip to content

Practice Construct the Lexicographically Largest Valid Sequence

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

Medium#1718
LeetCode Problem

Construct the Lexicographically Largest Valid Sequence

Problem Statement

Construct a sequence containing 1 once and every integer 2 through n twice. The two occurrences of each value i greater than 1 must have indices differing by exactly i. Return the lexicographically largest valid sequence; a solution is guaranteed to exist.

Source: Construct the Lexicographically Largest Valid Sequence on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

1 <= n <= 20

Related LeetCode Problems

Practice more problems similar to Construct the Lexicographically Largest Valid Sequence.

Review your practice with PhantomCodeAI

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