1866. Number of Ways to Rearrange Sticks With K Sticks Visible
On This Page
class Solution:
def rearrangeSticks(self, n: int, k: int) -> int:
mod = 10**9 + 7
f = [1] + [0] * k
for i in range(1, n + 1):
for j in range(k, 0, -1):
f[j] = (f[j] * (i - 1) + f[j - 1]) % mod
f[0] = 0
return f[k]