Find the N-th Value After K Seconds

You are given two integers n and k.

Initially, you start with an array a of n integers where a[i] = 1 for all 0 <= i <= n - 1. After each second, you simultaneously update each element to be the sum of all its preceding elements plus the element itself. For example, after one second, a[0] remains the same, a[1] becomes a[0] + a[1], a[2] becomes a[0] + a[1] + a[2], and so on.

Return the value of a[n - 1] after k seconds.

Since the answer may be very large, return it modulo 10^9 + 7.

Example 1
Inputn = 4, k = 5
Output56
After 5 seconds, the array becomes [1, 6, 21, 56], so a[n - 1] is 56.
Example 2
Inputn = 5, k = 3
Output35
After 3 seconds, the array becomes [1, 4, 10, 20, 35], so a[n - 1] is 35.

Constraints

  • 1 <= n, k <= 1000

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