In the Find the N-th Value After K Seconds coding problem, you have an array of elements, all initially 1. Every second, each element is updated to be the sum of all elements from to from the previous second. You need to return the value of the -th element after seconds, modulo .
Walmart Labs uses this to test whether you can move from Simulation to Combinatorics. While you can simulate the process in , if and are large, you need a mathematical solution. This problem is an application of Pascal's Triangle properties and Stars and Bars. It evaluations your ability to recognize that the -th element after seconds is a binomial coefficient.
There are two ways to solve this:
[1, 1, 1][1, 1+1, 1+1+1] [1, 2, 3][1, 1+2, 1+2+3] [1, 3, 6]
Result: 6.
Using formula: .Problems involving "running sums of running sums" are almost always related to Binomial Coefficients or the diagonals of Pascal's Triangle. If you see this pattern, try to map the steps to the formula.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find Triangular Sum of an Array | Medium | Solve | |
| Find the Count of Monotonic Pairs I | Hard | Solve | |
| Find the Count of Monotonic Pairs II | Hard | Solve | |
| Double Modular Exponentiation | Medium | Solve | |
| Find Missing Observations | Medium | Solve |