3179. Find the N-th Value After K Seconds Medium

@problem@discussion
#Array#Math#Simulation#Combinatorics#Prefix Sum



1/**
2 * [3179] Find the N-th Value After K Seconds
3 *
4 * You are given two integers n and k.
5 * 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.
6 * Return the value of a[n - 1] after k seconds.
7 * Since the answer may be very large, return it modulo 10^9 + 7.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 4, k = 5</span>
12 * Output: <span class="example-io">56</span>
13 * Explanation:
14 * <table border="1">
15 * 	<tbody>
16 * 		<tr>
17 * 			<th>Second</th>
18 * 			<th>State After</th>
19 * 		</tr>
20 * 		<tr>
21 * 			<td>0</td>
22 * 			<td>[1,1,1,1]</td>
23 * 		</tr>
24 * 		<tr>
25 * 			<td>1</td>
26 * 			<td>[1,2,3,4]</td>
27 * 		</tr>
28 * 		<tr>
29 * 			<td>2</td>
30 * 			<td>[1,3,6,10]</td>
31 * 		</tr>
32 * 		<tr>
33 * 			<td>3</td>
34 * 			<td>[1,4,10,20]</td>
35 * 		</tr>
36 * 		<tr>
37 * 			<td>4</td>
38 * 			<td>[1,5,15,35]</td>
39 * 		</tr>
40 * 		<tr>
41 * 			<td>5</td>
42 * 			<td>[1,6,21,56]</td>
43 * 		</tr>
44 * 	</tbody>
45 * </table>
46 * </div>
47 * <strong class="example">Example 2:
48 * <div class="example-block">
49 * Input: <span class="example-io">n = 5, k = 3</span>
50 * Output: <span class="example-io">35</span>
51 * Explanation:
52 * <table border="1">
53 * 	<tbody>
54 * 		<tr>
55 * 			<th>Second</th>
56 * 			<th>State After</th>
57 * 		</tr>
58 * 		<tr>
59 * 			<td>0</td>
60 * 			<td>[1,1,1,1,1]</td>
61 * 		</tr>
62 * 		<tr>
63 * 			<td>1</td>
64 * 			<td>[1,2,3,4,5]</td>
65 * 		</tr>
66 * 		<tr>
67 * 			<td>2</td>
68 * 			<td>[1,3,6,10,15]</td>
69 * 		</tr>
70 * 		<tr>
71 * 			<td>3</td>
72 * 			<td>[1,4,10,20,35]</td>
73 * 		</tr>
74 * 	</tbody>
75 * </table>
76 * </div>
77 *  
78 * Constraints:
79 * 
80 * 	1 <= n, k <= 1000
81 * 
82 */
83pub struct Solution {}
84
85// problem: https://leetcode.com/problems/find-the-n-th-value-after-k-seconds/
86// discuss: https://leetcode.com/problems/find-the-n-th-value-after-k-seconds/discuss/?currentPage=1&orderBy=most_votes&query=
87
88// submission codes start here
89
90impl Solution {
91    pub fn value_after_k_seconds(n: i32, k: i32) -> i32 {
92        0
93    }
94}
95
96// submission codes end
97
98#[cfg(test)]
99mod tests {
100    use super::*;
101
102    #[test]
103    fn test_3179() {
104    }
105}
106


Back
© 2025 bowen.ge All Rights Reserved.