3752. Lexicographically Smallest Negated Permutation that Sums to Target Medium
1/**
2 * [3752] Lexicographically Smallest Negated Permutation that Sums to Target
3 *
4 * You are given a positive integer n and an integer target.
5 * Return the <span data-keyword="lexicographically-smaller-array">lexicographically smallest</span> array of integers of size n such that:
6 *
7 * The sum of its elements equals target.
8 * The absolute values of its elements form a permutation of size n.
9 *
10 * If no such array exists, return an empty array.
11 * A permutation of size n is a rearrangement of integers 1, 2, ..., n.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">n = 3, target = 0</span>
16 * Output: <span class="example-io">[-3,1,2]</span>
17 * Explanation:
18 * The arrays that sum to 0 and whose absolute values form a permutation of size 3 are:
19 *
20 * [-3, 1, 2]
21 * [-3, 2, 1]
22 * [-2, -1, 3]
23 * [-2, 3, -1]
24 * [-1, -2, 3]
25 * [-1, 3, -2]
26 * [1, -3, 2]
27 * [1, 2, -3]
28 * [2, -3, 1]
29 * [2, 1, -3]
30 * [3, -2, -1]
31 * [3, -1, -2]
32 *
33 * The lexicographically smallest one is [-3, 1, 2].
34 * </div>
35 * <strong class="example">Example 2:
36 * <div class="example-block">
37 * Input: <span class="example-io">n = 1, target = 10000000000</span>
38 * Output: <span class="example-io">[]</span>
39 * Explanation:
40 * There are no arrays that sum to <span class="example-io">10000000000 and whose absolute values form a permutation of size 1. Therefore, the answer is [].</span>
41 * </div>
42 *
43 * Constraints:
44 *
45 * 1 <= n <= 10^5
46 * -10^10 <= target <= 10^10
47 *
48 */
49pub struct Solution {}
50
51// problem: https://leetcode.com/problems/lexicographically-smallest-negated-permutation-that-sums-to-target/
52// discuss: https://leetcode.com/problems/lexicographically-smallest-negated-permutation-that-sums-to-target/discuss/?currentPage=1&orderBy=most_votes&query=
53
54// submission codes start here
55
56impl Solution {
57 pub fn lex_smallest_negated_perm(n: i32, target: i64) -> Vec<i32> {
58 vec![]
59 }
60}
61
62// submission codes end
63
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn test_3752() {
70 }
71}
72Back
© 2026 bowen.ge All Rights Reserved.