Skip to content

Practice Find the N-th Value After K Seconds

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

Medium#3179
LeetCode Problem

Find the N-th Value After K Seconds

Problem Statement

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.

Source: Find the N-th Value After K Seconds on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 4, k = 5
Output
56

# Example 2

Input
n = 5, k = 3
Output
35

Constraints

1 <= n, k <= 1000

Related LeetCode Problems

Practice more problems similar to Find the N-th Value After K Seconds.

Review your practice with PhantomCodeAI

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