Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find the N-th Value After K Seconds

XPChallenge Points: 20
levelLevel: Medium

Start with a = [1, 1, ..., 1] of length n. Each second, update simultaneously:

a[i] := a[0] + a[1] + ... + a[i]

for all i. Return a[n-1] after k seconds, modulo 1_000_000_007.

Key fact: After k steps,

a[n1]  =  (n+k1k)  =  (n+k1n1).a[n-1] \;=\; \binom{n+k-1}{k} \;=\; \binom{n+k-1}{n-1}.

So compute a single binomial coefficient modulo 109+710^9+7.

Example 1:

Input: n = 5, k = 3

Output: 35

Example 2:

Input: n = 4, k = 5

Output: 56

Example 3:

Input: n = 1, k = 100

Output: 1

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result