Tap here to switch tabs
Problem
Submissions

Problem: Construct the Lexicographically Largest Valid Sequence

med
30 min
Try to solve the Construct the Lexicographically Largest Valid Sequence problem.

Statement

Given an integer n, construct a sequence of length 2imes2 imes n −1- 1 that satisfies the following conditions:

  • The integer 11 appears exactly once in the sequence.

  • Every integer i from 22 to n appears exactly twice in the sequence.

  • For each integer i between 22 and n, the distance between the two occurrences of i is exactly i. That is, if the first occurrence is at index j, the second occurrence is at index j + i.

Return the lexicographically largest valid sequence. It is guaranteed that a valid sequence always exists for the given constraints.

A sequence a is lexicographically larger than a sequence b of the same length if, at the first index where a and b differ, the element in a is greater than the element in b.

Constraints:

  • 1≤1 \leq n ≤20\leq 20

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct the Lexicographically Largest Valid Sequence

med
30 min
Try to solve the Construct the Lexicographically Largest Valid Sequence problem.

Statement

Given an integer n, construct a sequence of length 2imes2 imes n −1- 1 that satisfies the following conditions:

  • The integer 11 appears exactly once in the sequence.

  • Every integer i from 22 to n appears exactly twice in the sequence.

  • For each integer i between 22 and n, the distance between the two occurrences of i is exactly i. That is, if the first occurrence is at index j, the second occurrence is at index j + i.

Return the lexicographically largest valid sequence. It is guaranteed that a valid sequence always exists for the given constraints.

A sequence a is lexicographically larger than a sequence b of the same length if, at the first index where a and b differ, the element in a is greater than the element in b.

Constraints:

  • 1≤1 \leq n ≤20\leq 20