1866. Number of Ways to Rearrange Sticks With K Sticks Visible
https://leetcode.com/problems/number-of-ways-to-rearrange-sticks-with-k-sticks-visible
Description
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.
For example, if the sticks are arranged
[1,3,2,5,4]
, then the sticks with lengths1
,3
, and5
are visible from the left.
Given n
and k
, return the number of such arrangements. Since the answer may be large, return it modulo 109 + 7
.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= n <= 1000
1 <= k <= n
ac
Last updated