Tap here to switch tabs
Problem
Submissions

Problem: Smallest Negated Permutation That Sums to Target

Try to solve the Lexicographically Smallest Negated Permutation that Sums to Target problem.

Statement

Given two integers n and target, find an array of length n such that:

  • The absolute values of the elements form a permutation of the integers from 11 to n.

  • The sum of the elements in the array equals target.

Return the lexicographically smallest array that satisfies these conditions. If no such array exists, return an empty array [].

Note: An array a is lexicographically smaller than an array b of the same length if, at the first index where a and b differ, array a has an element strictly smaller than the corresponding element in b.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • −1010≤-10^{10} \leq target ≤1010\leq 10^{10}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Smallest Negated Permutation That Sums to Target

Try to solve the Lexicographically Smallest Negated Permutation that Sums to Target problem.

Statement

Given two integers n and target, find an array of length n such that:

  • The absolute values of the elements form a permutation of the integers from 11 to n.

  • The sum of the elements in the array equals target.

Return the lexicographically smallest array that satisfies these conditions. If no such array exists, return an empty array [].

Note: An array a is lexicographically smaller than an array b of the same length if, at the first index where a and b differ, array a has an element strictly smaller than the corresponding element in b.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • −1010≤-10^{10} \leq target ≤1010\leq 10^{10}