⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.

Sign in to watch this lesson
Algorithms - Recursion, Backtracking and Combinatorics · 5:04
Counting monotone grid paths by listing them gets hopeless fast (a 16 x 16 grid took about 6 s to enumerate here, and 18 x 18 has 15 times more), so we count them instead: a path is a choice of which steps go right, n choose k. We build Pascal's triangle from 'left plus above', see why it works under any modulus, avoid factorial overflow with the multiplicative formula and a 128-bit product, and then precompute factorials and inverse factorials modulo a prime (Fermat once, then a backward walk) so every C(n, k) is three lookups.