Categorygithub.com/szhou12/leetcode-goleetcode3179-Find-the-N-th-Value-After-K-Seconds
package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev

# README

3179. Find the N-th Value After K Seconds

Solution idea

Prefix Sum

  1. [1, 1, ..., 1]作为种子,算prefixSum算k次。

Time complexity = $O(k\cdot n)$

Pascal's Triangle

  1. Pascal's Triangle is a graphical representation of the binomial coefficients.
  2. The binomial coefficient $\binom{n}{k}$, in Pascal's Triangle, is the element at row $n$ and position $k$ (starting from 0).
  3. The value at position (n−1) after k seconds can be represented in Pascal's Triangle as: $\binom{n+k-1}{k}$ (why?)

91cdf945-4523-4448-bfb2-e09673c7aa96_1717907556 8382585

Time complexity = $O(\binom{n+k-1}{k})$