1866. Number of Ways to Rearrange Sticks With K Sticks Visible Hard
1/**
2 * [1866] Number of Ways to Rearrange Sticks With K Sticks Visible
3 *
4 * There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it.
5 *
6 * For example, if the sticks are arranged [<u>1</u>,<u>3</u>,2,<u>5</u>,4], then the sticks with lengths 1, 3, and 5 are visible from the left.
7 *
8 * Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 10^9 + 7.
9 *
10 * Example 1:
11 *
12 * Input: n = 3, k = 2
13 * Output: 3
14 * Explanation: [<u>1</u>,<u>3</u>,2], [<u>2</u>,<u>3</u>,1], and [<u>2</u>,1,<u>3</u>] are the only arrangements such that exactly 2 sticks are visible.
15 * The visible sticks are underlined.
16 *
17 * Example 2:
18 *
19 * Input: n = 5, k = 5
20 * Output: 1
21 * Explanation: [<u>1</u>,<u>2</u>,<u>3</u>,<u>4</u>,<u>5</u>] is the only arrangement such that all 5 sticks are visible.
22 * The visible sticks are underlined.
23 *
24 * Example 3:
25 *
26 * Input: n = 20, k = 11
27 * Output: 647427950
28 * Explanation: There are 647427950 (mod 10^9 + 7) ways to rearrange the sticks such that exactly 11 sticks are visible.
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= n <= 1000
34 * 1 <= k <= n
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible/
40// discuss: https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn rearrange_sticks(n: i32, k: i32) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_1866() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.