667. Beautiful Arrangement II Medium
1/**
2 * [667] Beautiful Arrangement II
3 *
4 * Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:
5 *
6 * Suppose this list is answer = [a1, a2, a3, ... , an], then the list [|a1 - a2|, |a2 - a3|, |a3 - a4|, ... , |an-1 - an|] has exactly k distinct integers.
7 *
8 * Return the list answer. If there multiple valid answers, return any of them.
9 *
10 * Example 1:
11 *
12 * Input: n = 3, k = 1
13 * Output: [1,2,3]
14 * Explanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1
15 *
16 * Example 2:
17 *
18 * Input: n = 3, k = 2
19 * Output: [1,3,2]
20 * Explanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= k < n <= 10^4
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/beautiful-arrangement-ii/
31// discuss: https://leetcode.com/problems/beautiful-arrangement-ii/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn construct_array(n: i32, k: i32) -> Vec<i32> {
37 vec![]
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_667() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.