Constructing Lexicographically Largest Valid Sequence For N
Construct Lexicographically Largest Valid Sequence: Use backtracking to build sequence with numbers 1-n twice, distance between occurrences equal to value. Reserve positions for subsequent occurrences.
1718. Construct the Lexicographically Largest Valid Sequence Difficulty: Medium Topics: Array, Backtracking Given an integer n, find a sequence 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 difference of their indices, |j - i|. Return the lexicographically largest sequence. It is guaranteed that under the given constraints, t...