Skip to content

Practice Number of Ways to Rearrange Sticks With K Sticks Visible

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1866
LeetCode Problem

Number of Ways to Rearrange Sticks With K Sticks Visible

Problem Statement

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. Given n and k, return the number of such arrangements. Since the answer may be large, return it modulo 10^9 + 7.

Source: Number of Ways to Rearrange Sticks With K Sticks Visible on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3, k = 2
Output
3

# Example 2

Input
n = 5, k = 5
Output
1

# Example 3

Input
n = 20, k = 11
Output
647427950

Constraints

1 <= n <= 1000
1 <= k <= n

Related LeetCode Problems

Practice more problems similar to Number of Ways to Rearrange Sticks With K Sticks Visible.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.