← All problemsSign in

1718. Construct the Lexicographically Largest Valid Sequence

LeetCodeArrayBacktrackingOpen on judge ↗

Given an integer n, find a sequence with elements in the range [1, n] that satisfies all of the following: - The integer 1 occurs once in the sequence. - Each integer between 2 and n occurs twice in the sequence. - For every integer i between 2 and n, the distance between the two occurrences of i is exactly i. The distance between two numbers on the sequence, a[i] and a[j], is the absolute dif

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start