Number of Sets of K Non-Overlapping Line Segments

Given n points on a 1-D plane, where the i^th point from 0 to n - 1 is at x = i, find the number of ways to draw exactly k non-overlapping line segments such that each segment covers two or more points.

The endpoints of each segment must have integral coordinates. The k line segments do not have to cover all n points, and they are allowed to share endpoints.

Return the number of ways to draw k non-overlapping line segments. Since this number can be huge, return it modulo 10^9 + 7.

Example 1
Inputn = 4, k = 2
Output5
The 5 ways are {(0,2),(2,3)}, {(0,1),(1,3)}, {(0,1),(2,3)}, {(1,2),(2,3)}, and {(0,1),(1,2)}.
Example 2
Inputn = 3, k = 1
Output3
The 3 ways are {(0,1)}, {(0,2)}, and {(1,2)}.

Constraints

  • 2 <= n <= 1000
  • 1 <= k <= n-1

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate